[英]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: strtotime是从1970-01-01(UTC)计算的,日期是使用我的时区,即America / New_York一个简单的例子:
Where timestamp is 0: 时间戳为0的位置:
var_dump(date('Y-m-d h:i:s', 0));
prints: 1969-12-31 07:00:00
打印:
1969-12-31 07:00:00
Where it should return 0, it returns 它应该返回0的地方,它返回
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. 但是,我到处都在使用
strtotime
函数。
I tried playing with the _$ENV['TZ']
and the date_timestamp_get()
; 我尝试使用
_$ENV['TZ']
和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. 我还将php.ini中的date.timezone修改为America / New_York,但仍然没有。
Finally, forcing the timezone using date_timestamp_set('UTC')
, works fine and both dates are synced. 最后,使用
date_timestamp_set('UTC')
强制时区,工作正常,两个日期同步。 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. h
!= H
日期。 It is 7pm, and you're trying to get the time from 1969-12-31 07:00:00am after. 现在是晚上7点,您想让时间从1969-12-31 07:00:00 am开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.