Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP wrong date/time

PHP date() & time() return incorrect time:

When date.timezone = "Europe/Riga" the time returned by date() was 03-12-2011 08:57:12, but system time was 03-12-2011 01:57:12 (timezone Europe/Riga - correct time at that moment). When I changed timezone to "Europe/London", the time changed to 03-12-2011 06:57:12 ( actual time 02-12-2011 23:57:12 )

Time returned by date / hwclock --show was correct (03-12-2011 01:57:12 with system timezone set as Riga)

OS: Debian 6.0

I have checked most of the questions regarding similar issues on SO/Google, but they all seem to have wrong timezone specified.

As far as I can tell there is problem between php -> os. Of course, because the incorrect time offset is always constant I could subtract difference, but it is not a proper solution.

Any ideas will be greatly appreciated.

like image 795
relic Avatar asked Dec 03 '11 00:12

relic


Video Answer


1 Answers

Reading PHP manual seems that behaviour of date.timezone is affected by settings in php.ini. There is another way to set the default timezone in all date/time function and it's the date_default_timezone_set. Try to set it with:

date_default_timezone_set('Europe/Riga');

instead of your date.timezone code.

like image 88
Marco Pace Avatar answered Sep 28 '22 21:09

Marco Pace