【问题标题】:Get the timestamp's timezone获取时间戳的时区
【发布时间】:2012-08-03 00:42:53
【问题描述】:

我想获取一个时间的时区,它与当地时间相同,但在另一个 GMT 地区。

这就是我认为可行的方法:

ceil((strtotime($scores[$i]['date'].' '.$scores[$i]['time'])-strtotime(date('d F Y H:i',strtotime("-2 hours"))))/3600)

但它给了我 -26 和 -22 等..

链接到测试站点,用于测试数据:[LINK DELETED]

感谢您的帮助。

【问题讨论】:

  • 如果您显示输入值是什么会很有帮助。一些随机的时间戳是无用的。像嵌套 strtotime() 调用这样的事情不是是一个好兆头。 timestamp->string->timestamp 是对 cpu 周期的无用浪费。
  • @MarcB 这不是随机的,这些日期在数据库中。服务器的 GMT 为 +2(我已在 FTP 上更新文件,请重新加载链接)
  • 它们对我们来说是随机的 - 显然这些数字是错误的时区,但由于我们无法看到这些时间值的来源,我们无法帮助您解决实际问题。你要求我们在烂房子上刷上一层新油漆,而忽略了房子已经烂了的事实。
  • @MarcB 它来自数据库,现在你可以看到我看到的日期,如果你刷新golvago.hu/cron.php 网站。
  • @MarcB 我回答你的问题了吗? :)

标签: php timezone gmt


【解决方案1】:

我找到了这个的逻辑,但我不知道为什么这样做,但现在,它工作正常......

代码:

if(ceil((strtotime($scores[$i]['date'].' '.$scores[$i]['time'])-strtotime(date('d FYH:i',strtotime (“-2 小时”))))/3600)

echo (ceil((strtotime($scores[$i]['date'].' '.$scores[$i]['time'])-strtotime(date('d FYH:i',strtotime ("-2 小时"))))/3600))+24;

}其他{

echo ceil((strtotime($scores[$i]['date'].' '.$scores[$i]['time'])-strtotime(date('d FYH:i',strtotime( “-2 小时”))))/3600); }

:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-23
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    相关资源
    最近更新 更多