php 将日期转换为 TZ 格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16516136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:16:50  来源:igfitidea点击:

convert date to T Z format

phpdate

提问by sandy

My date format is something like this

我的日期格式是这样的

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

I want the output as following.

我希望输出如下。

2013-05-07T06:17:55.827Z

Is there a simple way than using big functions ?

有没有比使用大函数更简单的方法?

采纳答案by Ja?ck

This should give the proper ISO8601 date/time in Z(ulu) timezone:

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

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

To do a date conversion:

要进行日期转换:

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

To have the additional .000(which is useless imho):

有额外的.000(这是无用的恕我直言):

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

回答by Eugene

Try this:

尝试这个:

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