【问题标题】:how to get timezone information如何获取时区信息
【发布时间】:2023-03-23 04:47:01
【问题描述】:

我有一个登录脚本,用于检查某个时间段是否已过。意识到我有一个时间戳,我用 strtotime 从我的数据库中获取,这样我就可以轻松地向这个时间/字符串添加一个秒值来检查这个特定的日期/时间是否已经过去。

昨天我更新到 php 5.3。现在我收到一条错误消息:

Warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /xxx/xxx/xxxx/xxx/login.php on line xx

在这条线上实现:

$DOA = strtotime($row->DOA);

问题是,我该如何使用:

date.timezone = "Europe/Berlin"
date.default_latitude = 52.5194
date.default_longitude = 13.4067

转换时间戳

$row->DOA

我必须得到一个字符串。还是这样的:

date.timezone = "Europe/Berlin"
date.default_latitude = 52.5194
date.default_longitude = 13.4067

只是我应该添加的信息,因为据说

We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead...

已使用。

如果有人可以给我建议来解决这个问题,我真的很感激。

【问题讨论】:

  • 问题标题与问题本身不匹配,甚至问题本身也很混乱。是否要获取客户端的时区?你想知道你的时区吗?您需要帮助来修复警告吗?你想在时区之间转换吗?
  • 你有'转换时间戳',我认为你的意思是'格式化的日期/时间字符串'而不是'时间戳'。

标签: php mysql datetime localization timezone


【解决方案1】:

我认为只是没有设置 PHP 时区。因此,您可以在 php.ini 中执行此操作,也可以在您的 php 文件中声明它。

date_default_timezone_set('Europe/Berlin');
$DOA = strtotime($row->DOA);

看看这是否能消除你的错误。

【讨论】:

  • 就是这样。我只需要添加这些信息。非常感谢。
【解决方案2】:

您可以使用此代码:

$timestamp = '1334826954';
$dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('Europe/Berlin'));
$dateTime->setTimestamp($timestamp);
echo $dateTime->format('Y-m-d H:i:s');

输出

2012-04-19 11:15:54

【讨论】:

  • 我看到你已经改变了问题。您不是在寻找将时间戳转换为格式化的日期/时间字符串,而是相反。
猜你喜欢
  • 1970-01-01
  • 2013-08-09
  • 1970-01-01
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
  • 2017-12-06
  • 2011-03-08
相关资源
最近更新 更多