简体   繁体   中英

php strtotime and date functions are using different timezones

strtotime is being calculated from 1970-01-01 (UTC) and date is using my timezone ie 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, obviously, I could add the timezone to the date ie

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM