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

2022-01-13 00:00:00 timestamp date 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)

相关文章