尽管时间戳正确,PHP 日期仍显示错误时间 [英] PHP date showing wrong time despite the timestamp being correct

查看:29
本文介绍了尽管时间戳正确,PHP 日期仍显示错误时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 PHP 日期函数的问题,我以前从未遇到过问题.

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

时间戳完全正确,但是由于某些奇怪的原因 date() 输出的时间不对应.

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); ?>

我的时间是凌晨 4 点?如果我将时间戳粘贴到时间戳转换器网站中,则显示时间实际上应该是上午 9 点.

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.

推荐答案

那个时间戳是 9am GMT 时区,如果你在另一个时区,那么你需要相应地调整它.

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');

在你的 php.ini 中甚至更好

or even better in your php.ini

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

date.timezone="Europe/London"

或者您可以更具体地使用 GMT 而不是欧洲/伦敦(有 DST)

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

这篇关于尽管时间戳正确,PHP 日期仍显示错误时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆