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

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

问题描述

我遇到了PHP date函数的问题,这是我以前从未遇到过的问题。

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.

推荐答案

该时间戳为格林尼治标准时间上午9点,如果您位于其他时区,则需要进行相应的调整。

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/zh/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天全站免登陆