[英]PHP - output of date('now') is a ahead of local time by 6 hours, but time zone is set to correct local zone zone?
I'm in St. Louis, MO in the USA Central Time Zone. 我在美国中央时区的密苏里州圣路易斯市。 We are -6 GMT
我们是-6 GMT
The PHP time zone setting in php.ini is date.timezone = "America/Chicago" php.ini中的PHP时区设置为date.timezone =“ America / Chicago”
(Chicago is almost directly north of St. Louis. (芝加哥几乎位于圣路易斯以北。
echo date('now'); 回声日期('现在'); produces: December 19, 2015, 2:45 am.
产生:2015年12月19日,凌晨2:45。 EDIT - I meant date("F j, Y, g:ia", strtotime("now"));, not date('now');
编辑-我的意思是date(“ F j,Y,g:ia”,strtotime(“ now”));,不是date('now');
Locally (by calendar and clock) it is December 18, 2015, 8:45 pm. 在当地(按日历和时钟)是2015年12月18日,晚上8:45。
Here is the date information as output by phpinfo() 这是phpinfo()输出的日期信息
date/time support enabled
"Olson" Timezone Database Version 2015.1
Timezone Database internal
Default timezone America/Chicago
Directive Local Value Master Value
date.default_latitude 31.7667 31.7667
date.default_longitude 35.2333 35.2333
date.sunrise_zenith 90.583333 90.583333
date.sunset_zenith 90.583333 90.583333
date.timezone America/Chicago America/Chicago
I thought that if the correct time zone is set, date('now') would return the local time and time - but I'm obliviously wrong. 我认为如果设置了正确的时区,则date('now')会返回本地时间和时间-但我显然是错的。
What am I missing about the date() function or PHP date handling in general? 我通常缺少有关date()函数或PHP日期处理的信息吗?
SimonT SimonT
There are a few different ways you can choose to handle this: 您可以选择几种不同的方式来处理此问题:
You can use date_default_timezone_set
to override Wordpress's time zone setting. 您可以使用
date_default_timezone_set
覆盖Wordpress的时区设置。
You can use the PHP DateTime
class instead of the date
function, which accepts a time zone in the constructor 您可以使用PHP
DateTime
类代替date
函数,该函数在构造函数中接受时区
You can change Wordpress's time zone setting in the WP Admin / Settings / General section: 您可以在WP管理员/设置/常规部分中更改Wordpress的时区设置:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.