Yii 设置日期默认时区错误



在用它的名字创建新的webapp之后。我现在收到此错误。

PHP警告

date(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone.

得到这个结果后,我把它写到配置数组:

'timeZone' => 'Asia/Tehran',

并索引.php:

Yii::app()->setTimeZone("UTC");

但这并没有改变任何事情,问题仍未解决。

我的默认系统日期是:

Tue Dec 31 14:11:49 IRST 2013

PHP.ini :

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
; http://php.net/date.default-latitude
;date.default_latitude = 31.7667
; http://php.net/date.default-longitude
;date.default_longitude = 35.2333
; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333
; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333

如果你不想碰你的php.ini文件

date_default_timezone_set("Asia/Tehran");

ini_set('date.timezone','Asia/Tehran');

更新
您也可以使用

ini_alter('date.timezone','Asia/Tehran');

但是不要忘记在调用任何日期函数之前调用它。

如错误中所述,您应该在 PHP ini 中设置date.timezone

; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Tehran

请注意,在 ini 文件中;是一个注释,因此已将其从 date.timezone 行中删除。

我会在 php.ini 文件中设置全局设置

date.timezone php 中.ini可以全局解决此问题。

仅在此处设置所有属性,然后重新启动 http 服务

如前所述,在php.ini中设置时区:date.timezone = Asia/Tehran

之后不要忘记重新启动您的网络服务器。

最新更新