dongyan3562 2015-04-08 21:59
浏览 78
已采纳

尽管时间戳正确,PHP日期显示错误的时间

I'm having a problem with the PHP date function which I've never had a problem with before.

The timestamp is entirely correct, however for some bizarre reason date() is outputting a time which does not correspond.

I have the following timestamp (and this is definitely the correct one - when I echo it out onto the page, as well as in the database, it shows as being correct):

464400

Yet when I use the following line of code:

<?php echo date("H:i",$timestamp); ?>

I'm getting a time of 4 am? If I paste the timestamp into a timestamp converter website, then it shows the time should in fact be 9am.

I'm completely stuck, this has never happened to me before & this problem has only just come up recently - the code hasn't been changed and everything seemed to be working correctly before.

Does anyone have any experience with this issue? Any help would be appreciated.

  • 写回答

3条回答 默认 最新

  • duandingcu7010 2015-04-08 22:03
    关注

    That time stamp is is 9am GMT timezone, if you are in another timezone then you will need to adjust it accordingly.

    http://php.net/manual/en/function.date-default-timezone-set.php

      date_default_timezone_set('Europe/London');
    

    or even better in your php.ini

    http://php.net/manual/en/datetime.configuration.php

    date.timezone="Europe/London"
    

    Or you can use more specifically GMT instead of Europe/London (which has DST)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大