How to convert ISO8601 to Date format in php

后端 未结 4 1691
耶瑟儿~
耶瑟儿~ 2020-11-30 07:54

How to convert this (in ISO8601 format): 2014-03-13T09:05:50.240Z

To this (in MySQL DATE format): 2014-03-13

4条回答
  •  独厮守ぢ
    2020-11-30 08:13

    try this

    $date = '2014-03-13T09:05:50.240Z';
    
    $fixed = date('Y-m-d', strtotime($date));
    

    The complete date function documentation can be found here: http://php.net/manual/en/function.date.php

    The PHP function "strtotime" does nothing else then converting your timestring into an unix timestamp.

    Hope I could help :)

    P.s.: Just in case strtotime will return 0 try using this:

    $date = '2014-03-13T09:05:50.240Z';
    
    $fixed = date('Y-m-d', strtotime(substr($date,0,10)));
    

提交回复
热议问题