문제

If I run the following in PHP:

echo mktime(0,0,0,1,1,1970);

the returned value is -3600, not 0 as I expected.

The server is UK based, it's currently 21 Sep (i.e. BST summertime) (though I wouldn't expect this to affect the epoch timestamp) and per php.info: "Default timezone Europe/London".

Setting the daylight saving time flag also, as follows, gives:

echo mktime(0,0,0,1,1,1970,0); (i.e. the correct DST flag, 0 as 1 Jan not DST/BST) returns -3600

echo mktime(0,0,0,1,1,1970,1); (the incorrect flag - setting 1 Jan as DST) returns -7200

echo mktime(0,0,0,1,1,1970,-1); (i.e. DST flag not set - left to PHP to decide) returns -3600

Does anyone know why the epoch would be returned as -3600, not 0, please?

도움이 되었습니까?

해결책

When it was midnight on Jan 1st 1970 in British Summer Time, it was one hour to midnight in Greenwich Mean Time. Try setting the time zone to UTC instead:

date_default_timezone_set('UTC'); // or just change php.ini

다른 팁

mktime() is based on your current timezone. If you want to create a timestamp based on GMT you have to use the gmmktime() function.

gmmktime(0,0,0,1,1,1970)

code on ideone


Resources :

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top