timezone - PHP and DST conversion issue -


i'm having trouble understanding how code adapts dst, it's incorrect recent update. i'm storing date time in database based on utc , converting local timezone display. if php taking dst account, else wrong because of stored dates 1 hour off.

$stored_date = '2016-11-16 12:04:01'; // in utc  $datetime = new datetime($stored_date, new datetimezone('utc')); $datetimezone = new datetimezone('america/new_york'); $datetime->settimezone($datetimezone);  print_r($datetime); 

last week, before dst ended, have printed out 2016-11-16 08:04:01. week, dst has ended, prints out 2016-11-16 07:04:01. why hour difference if php handing dst shift?

it shouldn't matter server settings (i don't think) because i'm explicitly doing conversion within php, right?

i'm ready start doing check php see if dst in effect , offsetting conversion 1 hour because can't figure out why hour isn't being automatically compensated within datetime class.

new york city switches between these time zones:

  • winter: est (eastern standard time) = utc -5
  • summer: edt (eastern daylight time) = utc -4

according timeanddate.com switch happen on 6th of november. result correct: 12 - 5 = 7

in other words, php aware of dst, can see in following code:

$datetime = new datetime('2016-11-05 12:04:01', new datetimezone('utc')); $datetime->settimezone(new datetimezone('america/new_york')); echo $datetime->format('r') . php_eol;  $datetime = new datetime('2016-11-06 12:04:01', new datetimezone('utc')); $datetime->settimezone(new datetimezone('america/new_york')); echo $datetime->format('r') . php_eol; 
sat, 05 nov 2016 08:04:01 -0400 sun, 06 nov 2016 07:04:01 -0500 

you can inspect exact information available in system's time database:

$timezone = new datetimezone('america/new_york'); print_r($timezone->gettransitions(mktime(0, 0, 0, 1, 1, 2016), mktime(0, 0, 0, 12, 31, 2016))); 
array (     [0] => array         (             [ts] => 1451602800             [time] => 2015-12-31t23:00:00+0000             [offset] => -18000             [isdst] =>              [abbr] => est         )      [1] => array         (             [ts] => 1457852400             [time] => 2016-03-13t07:00:00+0000             [offset] => -14400             [isdst] => 1             [abbr] => edt         )      [2] => array         (             [ts] => 1478412000             [time] => 2016-11-06t06:00:00+0000             [offset] => -18000             [isdst] =>              [abbr] => est         )  ) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -