将日期转换为T Z格式

时间:2013-05-13 06:38:26

标签: php date

我的日期格式是这样的

2013-05-07 18:56:57 (yyyy-MM-dd hh:mm:ss)

我希望输出如下。

2013-05-07T06:17:55.827Z

有没有比使用大功能更简单的方法?

2 个答案:

答案 0 :(得分:27)

试试这个:

 date("Y-m-d\TH:i:s.000\Z", strtotime("2013-05-07 18:56:57"));

答案 1 :(得分:11)

这应该在Z(ulu)时区中给出正确的ISO8601日期/时间:

str_replace('+00:00', 'Z', gmdate('c'))

进行日期转换:

str_replace('+00:00', 'Z', gmdate('c', strtotime('2013-05-07 18:56:57')))

要获得额外的.000(这是无用的imho):

str_replace('+00:00', '.000Z', gmdate('c', strtotime('2013-05-07 18:56:57')))
相关问题