php strtotime and date functions are using different timezones
strtotime is being calculated from 1970-01-01 (UTC) and date is using my timezone i.e America/New_York A simple example:
Where timestamp is 0:
var_dump(date('Y-m-d h:i:s', 0));
prints: 1969-12-31 07:00:00
Where it should return 0, it returns
var_dump(strtotime('1969-12-31 07:00:00'));
-43200
Now, obvi开发者_如何学编程ously, I could add the timezone to the date i.e
strtotime($date . ' -5')
and it'd work.
But, I'm using the strtotime
function everywhere.
I tried playing with the _$ENV['TZ']
and the date_timestamp_get()
;
But I can't sync them.
I also modified the date.timezone in php.ini to America/New_York and still nothing.
Finally, forcing the timezone using date_timestamp_set('UTC')
, works fine and both dates are synced. But, I need the timezone from the server.
Please advise, I'm out of ideas
var_dump(date('Y-m-d H:i:s', 0));
h
!= H
in date. It is 7pm, and you're trying to get the time from 1969-12-31 07:00:00am after.
精彩评论