[英]PHP strtotime function give different result on same date on different servers
I am using strtotime
function with 28th October, 2014 date like echo strtotime('2014-10-28')
on local and staging servers. 我在2014年10月28日使用
strtotime
函数,例如在本地和登台服务器上使用echo strtotime('2014-10-28')
。
Local server result: 1414468800 本地服务器结果:1414468800
Staging server result: 1414425600 登台服务器结果:1414425600
Why there is difference between the results on different servers and how can I fix this issue? 为什么在不同服务器上的结果之间存在差异,如何解决此问题?
i think it is because the two servers have diff timezones.. 我认为这是因为两台服务器的时区不同。
you can atleast do this: 您可以至少这样做:
$date = '2014-10-28'; // date
$timezone = 'America/Virgin'; // timezone you prefer
$date = new DateTime($date , new DateTimeZone($timezone));
echo $date->getTimestamp();
You can set the timezone in your php.ini
file. 您可以在
php.ini
文件中设置时区。 The value is 值是
date.timezone = "Americas/New_York"
I think this values are different on your systems. 我认为这个值在您的系统上是不同的。
Otherwise you have to set it in your scripts but i think its better to set it in your configuration. 否则,您必须在脚本中进行设置,但我认为最好在您的配置中进行设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.