简体   繁体   中英

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. This is my post 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM