10

Am using strtotime to get seconds past 1 January 1970, but am not understanding that why am getting -3600 if the clock is set to 12.00AM and I get 0 when the clock is set to 1 AM, so what's with that 1 HOUR? Is it an issue with the timezone?

echo 'I Expect 0 Here '.strtotime('1st January 1970').'<br />';
//This gives me -3600

echo 'I Expect 3600 Here '.strtotime('1st January 1970 01.00AM'); 
//This gives me 0

P.S I've not set any Time Zone in my PHP file or I've not even modified my .ini file (Fresh Installed XAMPP)

Update : Time-Zone : Europe/Berlin

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278

4 Answers4

8

It's most likely due to your local time zone.
What's the output of

var_dump(date_default_timezone_get());

on that machine?
You can also check the difference between mktime and gmmktime

echo " mktime: ", mktime(), "\n";
echo " gmmktime: ", gmmktime(), "\n";
VolkerK
  • 95,432
  • 20
  • 163
  • 226
6

Your timezone must be set to UTC+1. Midnight in your timezone happened an hour before midnight in UTC, which explains the offset of -3600 seconds.

You can set the timezone to UTC to get the expected result:

date_default_timezone_set('UTC');
Joni
  • 108,737
  • 14
  • 143
  • 193
5

You need to check your time zone settings. or if you set the default_time_zone to UTC, you will get the desired result.

date_default_timezone_set('UTC');
Adeel
  • 19,075
  • 4
  • 46
  • 60
1

add this to set timezone 'Europe/Berlin'

 date_default_timezone_set('Europe/Berlin');
thumber nirmal
  • 1,639
  • 3
  • 16
  • 27