PHP date showing wrong time despite the timestamp being correct(尽管时间戳正确,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 日期仍显示错误时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:尽管时间戳正确,PHP 日期仍显示错误时间


- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Laravel 仓库 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01