开发者

PHP date formatting issue

开发者 https://www.devze.com 2023-01-10 05:22 出处:网络
This PHP statementdate(\'Y-m-d\',1281394800) returns different values in different servers.One gives me 2010-08-09 and the other 2010-08-10.Could s开发者_开发技巧omeone please help explain?Try this an

This PHP statement date('Y-m-d',1281394800) returns different values in different servers. One gives me 2010-08-09 and the other 2010-08-10. Could s开发者_开发技巧omeone please help explain?


Try this and see if you still get different results:

date_default_timezone_set('UTC');
echo date('Y-m-d',1281394800);

If you get exactly the same results across servers, you can set the timezone to the one you want. For more information:

date_default_timezone_set

List of Supported Timezones


Are the servers in (or configured with) different timezones?

date()'s output is timezone-dependent.


Set the time zone:

date_default_timezone_set('UTC');
echo date('Y-m-d',1281394800);

date_default_timezone_set — Sets the default timezone used by all date/time functions in a script

  • http://php.net/manual/en/function.date-default-timezone-set.php
  • List of Supported Timezones
0

精彩评论

暂无评论...
验证码 换一张
取 消