[英]Parse custom date and time by user through postman
I wanted to pass the custom data through postman but the problem is how do I parse date and time in a field at time? 我想通过邮递员传递自定义数据,但是问题是我该如何在某个时间解析字段中的日期和时间? Initially I tried strtotime function but I wanted it along with the date.
最初,我尝试了strtotime函数,但我希望将其与日期一起使用。 This is my post API:
这是我的帖子API:
$post = Auth::user()->posts()->create([
'user_id' => Auth::id(),
'post_id' => rand(),
'title' => $request->title,
'time' => strtotime($request->time),
]);
One option 一种选择
$in = '22-04-19 12:00:01';
echo date('Y-m-d H:i:s',strtotime($in));
RESULT 结果
2022-04-19 12:00:01
A slightly more reliable method 一种更可靠的方法
$date = DateTime::createFromFormat('y-m-d H:i:s', $in);
echo $date->format('Y-m-d H:i:s');
RESULT 结果
2022-04-19 12:00:01
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.