【问题标题】:PHP Display a unix timestamp in GMT [duplicate]PHP在GMT中显示一个unix时间戳[重复]
【发布时间】:2015-08-06 06:02:00
【问题描述】:

我有一个存储在 mysql 中的 unix 时间戳:

1438919940 

当我在http://www.onlineconversion.com/unix_time.htm 转换它时,它显示为

Fri, 07 Aug 2015 03:59:00 GMT // this is how I want to display it

在我的代码中,我使用以下方式显示它:

$published = $row['update_date'];  //this is where 1438919940 comes from
$published = date ('jS F y @ g:ia',$published);
echo $published; 

但这显示为

7th August 15 @ 3:59am

我做的原始 strtotime 是 PDT 时间,我的服务器设置为 Europe/London,在我的脚本中我有

date_default_timezone_set('Europe/London'); 

在线转换网站如何将其与“正确”(我想要的)版本相呼应,并且我正在获得未来的约会!

【问题讨论】:

  • 以 GMT 格式存储日期和时间,并根据用户时区运行时更改时区
  • 你以后怎么约会?还是 2015 年 8 月 7 日凌晨 3:59?也许您需要“gmdate”而不仅仅是“date”?

标签: php date unix-timestamp


【解决方案1】:

请尝试

date_default_timezone_set("GMT");
$published = $row['update_date'];
$published = date ('D, d M Y H:i:s T',$published);
echo $published;

请参阅以下链接了解日期格式: http://php.net/manual/en/function.date.php

【讨论】:

  • 欢迎来到 SE!这看起来是一个很好/正确的答案。但是,我认为可以通过添加例如来改进它。关于格式说明符的小解释和/或解释它的参考链接。
  • 感谢 andreas 的建议。
  • GMT 和 UTC 相同。
  • @DeniGeorge 现在显示为 2015 年 8 月 7 日星期五 03:59:00 GMT - 明天又是明天!!
  • 结果是正确的。参见例如unixtimestamp.com : 1438919940 相当于:08/07/2015 @ 3:59am (UTC) 该日期是否在未来无关紧要。就是时间戳对应的时间。
猜你喜欢
  • 1970-01-01
  • 2013-05-28
  • 1970-01-01
  • 2012-04-24
  • 1970-01-01
  • 2017-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多