简体   繁体   中英

PHP $date->format(DateTime::ISO8601) returning different timezone offset

Ok, i'm stumped. Here are two date objects i have:

// $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',
))

They both have the exact same timezone information. However when i run $startDate->format(DateTime::ISO8601) and $endDate->format(DateTime::ISO8601) I get different timezone offsets.

// $startDate->format(DateTime::ISO8601)
2017-11-05T00:00:00-0500

// $endDate->format(DateTime::ISO8601)
2017-11-05T23:59:00-0600

Any idea as to what may be causing this?

-0500 and -0600 in DateTime::ISO8601 format are not a timezones, but offsets from UTC.

Starting from 2 am Sunday, 12 March 2017, the offset is -6:00 from UTC. At 2 am Sunday, 5 November, 2017 DST will be turned off. Since then the offset will be 1 hr less till next DST switchover.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM