【发布时间】:2014-10-30 20:25:27
【问题描述】:
我的 php 日期函数有一个令人恼火的问题,它获取了错误的时间。
我正在使用 ubuntu 12.04LTS 和 php 版本 5.3.10-1ubuntu3.13
我的系统时间是正确的:
#sudo hwclock --debug
hwclock from util-linux 2.20.1
Using /dev interface to clock.
Last drift adjustment done at 1409943046 seconds after 1969
Last calibration done at 1409943046 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2014/09/05 20:11:17
Hw clock time : 2014/09/05 20:11:17 = 1409947877 seconds since 1969
Fri 05 Sep 2014 21:11:17 BST -0.550945 seconds
#date
Fri Sep 5 21:12:23 BST 2014
但是,如果我使用日期,我会得到:
TIME STAMP: 1409944442
DATE (M/D/Y @ h:m:s): 09 / 05 / 14 @ 7:14:02pm UTC
在我的 php 代码中,我有这个:
date_default_timezone_set('欧洲/伦敦');
当前时间比这个时间提前了 2 小时。如果在我做date('I') 时检测到夏令时是真的,但这只需要我到晚上 8 点,我还需要一个额外的小时。
我没有更改我的 php.ini 我确实运行了 ntp 服务,如果它是正确的时间(不确定是否需要该信息?)
感谢您的帮助
【问题讨论】:
-
它们是两个不同的时区。您需要将时间戳从 UTC 转换为服务器的当前时区。
标签: php