且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP中的DateTime构造函数

更新时间:2022-06-14 22:36:46

显然,这不是错误,它是预期的 ,但没有记录的行为'查看对错误报告的评论 。所有单个字母( j除外)都代表军事时区,请参阅一些代码来演示这一点

Apparently, this is not a bug, it is 'expected, but undocumented behaviour'See the comments to the bug report. All single letters (except for 'j') represent military timezones, see some code to demonstrate this.

有更多信息此处

来自 RFC822


军事标准在每个区域使用一个字符。 Z是世界标准时间。 A表示提前一小时, M表示提前十二小时; N是一小时后, Y是十二小时后。

The military standard uses a single character for each zone. "Z" is Universal Time. "A" indicates one hour earlier, and "M" indicates 12 hours earlier; "N" is one hour later, and "Y" is 12 hours later. The letter "J" is not used.

所以回答您的问题

我不明白这一点,它是如何工作的?

I am not getting the point, how it's working?

当DateTime :: __ construct()时传递了一个不是有效时间字符串的单一值,它假定第一个参数已被省略,并尝试将字符串解析为时区。正如RFC解释的那样, x是有效的时区,因此您将获得位于时区 X中的DateTime实例。

When DateTime::__construct() is passed a single value that is not a valid time string it assumes that the first parameter has been omitted and tries to parse the string as a time zone. As the RFC explains, 'x' is a valid timezone, so you will get a DateTime instance that is in timezone 'X'.

我应该提到,尽管构造函数的\DateTime识别这些单个字母区域,\DateTimeZone的构造函数不会!

I should mention that although the constructor of \DateTime recognises these single letter zones, the constructor of \DateTimeZone does not!

我希望能帮上忙。