日期时区类中的奇怪连续性


Strange contants in DateTimeZone class

DateTimeZone 类中有奇怪的常量

class DateTimeZone {
    const UTC = 1024;
    const ALL = 2047;
    ...
}

我试图找到有关它们的任何信息。也尝试使用它们:

$dtz = new DateTimeZone(DateTimeZone::UTC); // throws Exception with message 
                                            // DateTimeZone::__construct(): Unknown or bad timezone (1024)

$dt = new Datetime('2016-02-01 10:00:00', DateTimeZone::UTC); // throws Exception with message
                                                              // DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given

它们的用途以及如何使用它们?

它们

用于一些地方,例如 DateTimeZone::listIdentifiers ,它将DateTimeZone::EUROPE之类的东西作为参数(并会为您提供所有Europe/Whatever时区的列表)。

您不能使用它们来创建DateTimeZoneDateTime因为它们是多个时区的区域组,而不是特定的单个时区(UTC 可能在这里让您感到困惑)。