PHP获取用户的时区

时间:2013-11-11 04:26:57

标签: php timezone

更改服务器后,我收到以下错误...

<b>Warning</b>:  date() [<a href='function.date'>function.date</a>]: 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 'America/New_York' for
'EST/-5.0/no DST' instead in <b>/sessions.php</b> on line <b>8001</b>

此错误消息引用的行是......

$date = date('Y-m-d G:i:s');

我不确定这是怎么回事?

那么如何获取用户的时区,然后将其设置为内置PHP变量或将其与date()一起使用?

2 个答案:

答案 0 :(得分:2)

如警告所述,您应该:

  1. 在php.ini中设置date.timezone;或
  2. 在致电date_default_timezone_set()
  3. 之前设置date()

答案 1 :(得分:1)

在php.ini文件中设置时区