如何在PHP中获取带有时区的ISO 8601格式的时间戳 [英] How to get timestamp in ISO 8601 format with timezone in php
问题描述
基于 wix文档, 2014-04-16T11:16:27.930Z 是 ISO 8601 格式的带有时区的时间戳。
快速研究发现, ISO 8601 中的时间戳显示的时区带有+ time_interval(例如+00:00)
Based on the wix documentation, 2014-04-16T11:16:27.930Z is a timestamp in ISO 8601 format with a timezone. A quick research reveals that the timestamp in ISO 8601 displays the timezone with +time_interval (for instance +00:00)
我尝试显示以下内容的date('c'):2014-04-16T06:23:31 + 00:00
I tried date('c') which displays: 2014-04-16T06:23:31+00:00
有人可以告诉我如何在中显示时间戳> 2014-04-16T11:16:27.930Z 而不是 2014-04-16T06:23:31 + 00:00
Could anyone tell me how to display timestamp in 2014-04-16T11:16:27.930Z rather than 2014-04-16T06:23:31+00:00
推荐答案
考虑有关UTC ISO_8601 UTC的维基百科文章可以将偏移量定义为Hour:Minutes定义为HoursMinutes定义。
Considering the Wikipedia Article on ISO_8601 the UTC Offset can be defined as a Hour:Minutes Definition of as a HoursMinutes Definition.
Z是零UTC偏移量的区域标记。 09:30 UTC因此,表示为 09:30Z。或 0930Z。 14:45:15 UTC将为 14:45:15Z
Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z".
PHP date方法将参数Z定义为
The PHP date method defines the parameter Z as
Z时区偏移量(以秒为单位)。 UTC以西的时区的偏移量始终为负,而UTC以东的时区的偏移量始终为正。
Z Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.
因此,假设维基百科文章中提到的偏移量为您可以在几秒钟内使用日期创建自己的 ISO 8601
。当前服务器时间/日期的示例:
So assuming the offset mentioned in the wikipedia article is in seconds, you could create your own ISO 8601
using date. Example given for current server time/date:
date('Y-m-d\TH:i:s.Z\Z', time());
此外,正如@AndrewIsOffline的注释中所述,因为 PHP5 ,使用'c'还可以得到ISO 8601日期:
Also, as mentioned in the comments by @AndrewIsOffline, since PHP5, using 'c' will also give you the ISO 8601 Date:
date('c', time());
这篇关于如何在PHP中获取带有时区的ISO 8601格式的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!