dongtan8979 2015-12-19 02:52
浏览 139
已采纳

PHP - 日期('now')的输出比本地时间提前6小时,但是时区设置为更正本地区域区域?

I'm in St. Louis, MO in the USA Central Time Zone. We are -6 GMT

The PHP time zone setting in php.ini is date.timezone = "America/Chicago"

(Chicago is almost directly north of St. Louis.

echo date('now'); produces: December 19, 2015, 2:45 am. EDIT - I meant date("F j, Y, g:i a", strtotime("now"));, not date('now');

Locally (by calendar and clock) it is December 18, 2015, 8:45 pm.

Here is the date information as output by 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.

What am I missing about the date() function or PHP date handling in general?

SimonT

  • 写回答

1条回答 默认 最新

  • dongzhouhao4316 2015-12-19 16:18
    关注

    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.

    • You can use the PHP DateTime class instead of the date function, which accepts a time zone in the constructor

    • You can change Wordpress's time zone setting in the WP Admin / Settings / General section:

    screenshot

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。