does php's date_default_timezone_set adjust to daylight saving?

拜拜、爱过 提交于 2019-11-30 03:33:43

问题


Does php's date_default_timezone_set adjust to daylight saving?

I have this code, and wonder if it will always result in the correct Stockholm time?

  date_default_timezone_set('Europe/Stockholm');
  $timestamp = date("Y-m-d H:i:s");

回答1:


Yes this should always result in the right time.




回答2:


PHP doesn't handle DST automatically. You have to check

if (date('I', time()) == 1) ... the time is in DST mode ("0" = not)

Then you should adust time accordingly. (Note: 'I' in capital. I have just checked it and it works.)




回答3:


As long as your timezone is listed in the following link, timestamp should be relative to the correct timezone.

http://www.php.net/manual/en/timezones.php



来源:https://stackoverflow.com/questions/7660240/does-phps-date-default-timezone-set-adjust-to-daylight-saving

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!