JSON Array to PHP DateTime

后端 未结 2 1403
太阳男子
太阳男子 2021-01-23 03:06

How do I get PHP Date Time from a JSON?

$params = array();
 $content = json_decode($request->getContent(), true);
 if(empty($content))
{
   throw         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-23 03:26

    I assume that echo "

    ";print_r($content); is given data like below:-

    Array
    (
        [date] => 2017-02-15 15:20:14
    )
    

    So do like below:-

    echo date ('Y-m-d H:i:s',strtotime($content['date'])); // normal date conversion
    
    echo PHP_EOL;
    
    $dateTime = new DateTime($content['date']); // datetime object
    
    echo $dateTime->format('y-m-d H:i:s');
    

    Output:-https://eval.in/738434

提交回复
热议问题