wamp服务器中错误的PHP日期()输出

问题描述:

问题是 date('r') 为我的时区返回了错误的时间.

The problem is that date('r') returns wrong time for my timezone.

php.ini 时区设置:
date.timezone = 欧洲/基辅

php.ini timezone setting:
date.timezone = Europe/Kiev

date_default_timezone_set('Europe/Kiev') 在我的脚本中解决了这个问题.

date_default_timezone_set('Europe/Kiev') in my script solves the problem.

WAMP 有什么问题?

So what's wrong with WAMP?

我建议总是使用 date_default_timezone_set() 来自脚本

I suggest always using date_default_timezone_set() from script

例如

date_default_timezone_set('Europe/Kiev');

ini_set('date.timezone', 'Europe/Kiev');

...避免 PHP 猜测时区.

...to avoid PHP guessing timezone.

当您将代码传输到不同的服务器(例如,乌克兰境外)时,它会派上用场.如果 date.timezone 未在 php.ini 中设置或其设置不正确,此行将帮助您避免意外(错误)结果.当您无法访问和/或修改 php.ini(共享主机)时,它也很方便.

It comes handy when you transfer code to different server(s), for example, outside of Ukraine. This line should help you to avoid unexpected (wrong) results if date.timezone is not set in php.ini or its setting is incorrect. It's also handy when you can't access and/or modify php.ini (shared hosting).

另外,请确保您没有在 php.ini 中的和 of 行使用 ;.

Also, be sure that you've not used ; at the and of line in php.ini.

更改php.ini后重启服务器.