Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does php's date_default_timezone_set adjust to daylight saving?

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");
like image 621
Robin Manoli Avatar asked Oct 05 '11 10:10

Robin Manoli


1 Answers

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.)

like image 155
Apostolos Avatar answered Nov 12 '22 15:11

Apostolos