PHP $date->format(DateTime::ISO8601) 返回不同的时区偏移量
PHP $date->format(DateTime::ISO8601) returning different timezone offset
好吧,我被难住了。这是我的两个日期对象:
// $startDate value
DateTime::__set_state(array(
'date' => '2017-11-05 00:00:00.000000',
'timezone_type' => 3,
'timezone' => 'America/Chicago',
))
// $endDate value
DateTime::__set_state(array(
'date' => '2017-11-05 23:59:00.000000',
'timezone_type' => 3,
'timezone' => 'America/Chicago',
))
它们都有完全相同的时区信息。然而,当我 运行 $startDate->format(DateTime::ISO8601)
和 $endDate->format(DateTime::ISO8601)
我得到不同的时区偏移量。
// $startDate->format(DateTime::ISO8601)
2017-11-05T00:00:00-0500
// $endDate->format(DateTime::ISO8601)
2017-11-05T23:59:00-0600
知道是什么原因造成的吗?
-0500
和 DateTime::ISO8601
格式的 -0600
不是时区,而是与 UTC 的偏移量。
从 2017 年 3 月 12 日星期日凌晨 2 点开始,与 UTC 的偏移量为 -6:00。 2017 年 11 月 5 日(星期日)凌晨 2 点将关闭 DST。从那时起,偏移将减少 1 小时,直到下一次 DST 切换。
好吧,我被难住了。这是我的两个日期对象:
// $startDate value
DateTime::__set_state(array(
'date' => '2017-11-05 00:00:00.000000',
'timezone_type' => 3,
'timezone' => 'America/Chicago',
))
// $endDate value
DateTime::__set_state(array(
'date' => '2017-11-05 23:59:00.000000',
'timezone_type' => 3,
'timezone' => 'America/Chicago',
))
它们都有完全相同的时区信息。然而,当我 运行 $startDate->format(DateTime::ISO8601)
和 $endDate->format(DateTime::ISO8601)
我得到不同的时区偏移量。
// $startDate->format(DateTime::ISO8601)
2017-11-05T00:00:00-0500
// $endDate->format(DateTime::ISO8601)
2017-11-05T23:59:00-0600
知道是什么原因造成的吗?
-0500
和 DateTime::ISO8601
格式的 -0600
不是时区,而是与 UTC 的偏移量。
从 2017 年 3 月 12 日星期日凌晨 2 点开始,与 UTC 的偏移量为 -6:00。 2017 年 11 月 5 日(星期日)凌晨 2 点将关闭 DST。从那时起,偏移将减少 1 小时,直到下一次 DST 切换。