php - 如何获取时区信息

标签 php mysql datetime localization timezone

我有一个登录脚本,用于检查某个时间段是否已过。意识到我有一个时间戳,我从我的数据库中使用 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 时区。所以您可以在 php.ini 中执行此操作或在您的 php 文件中声明它。

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

看看这是否消除了您的错误。

关于php - 如何获取时区信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10224768/

相关文章:

perl - 如何在 Perl 中转换时区?

PHP:两个相同的日期语句,但其中一个的星期几是错误的

php - Heroku deploy 自动删除服务器文件?

php - 我可以自动发布带有 future 时间戳的文章吗?

mysql - 如何在MySQL中选择所有以特定数字开头的列数据

python - 在python中找到2次之间差异的最简单方法是什么?

python - 如何组合日期列和时间列

php - 插入使用同一行(相同的主键)mysql php pdo

javascript - jquery-autocomplete:serviceUrl来过滤lookupFilter()中显示的结果

python - 在 MySQL 上部署 Django 给出 #1071 错误 "Specified key was too long"