如何在php中将ISO8601转换为日期格式

如何在php中将ISO8601转换为日期格式

问题描述:

如何转换(ISO8601 格式): 2014-03-13T09:05:50.240Z

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

至此(在 MySQL DATE 格式): 2014-03-13

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

在 php 中?

试试这个

$date = '2014-03-13T09:05:50.240Z';

$fixed = date('Y-m-d', strtotime($date));

完整的日期函数文档可以在这里找到:http://php.net/手册/en/function.date.php

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

PHP 函数strtotime"除了将您的时间字符串转换为 unix 时间戳之外什么都不做.

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

希望我能帮上忙:)

附言:以防万一 strtotime 将返回 0 尝试使用这个:

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)));