欢迎来到 Android人的问与答 ,在这里提问或帮助他人解答。 Question2Answer的1.6.x和1.7.x版本的中文翻译包我修改更新:

Question2answer

如何使用中文语言包

Q2A 1.6.x - Chinese Simplified (简体中文)

Q2A 1.7.x - Chinese Simplified (简体中文)


国内服务器推荐 阿里云服务器
国外服务器推荐 DigitalOcean
VPN推荐 正版Green VPN
阿里云推荐码:ldvq50

date(): It is not safe to rely on the system's timezone settings in CodeIgniter

0 喜欢 0 不喜欢
230 浏览

PHP代码中调用date()时,遇到如题的错误。

原因是:服务器没有配置时区。

解决方法有两种:

1.修改php.ini

You probably need to put the timezone in a configuration line in your php.ini file. You should have a block like this in your php.ini file:

[Date]

; Defines the default timezone used by the date functions

; http://php.net/date.timezone

date.timezone = America/New_York

If not, add it (replacing the timezone by yours). After configuring, make sure to restart httpd (service httpd restart).

Here is the list of supported timezones.

2.修改调用地方的代码

If you cannot modify your php.ini configuration, you could as well use the following snippet at the beginning of your code:

date_default_timezone_set('Africa/Lagos');//or change to whatever timezone you want

The list of timezones can be found at http://www.php.net/manual/en/timezones.php.

另外,还有奇葩的解决方案:

Add the following in your index.php file. I first came across this when I moved my application from my XAMPP server to Apache 2.2 and PHP 5.4...

I would advise you do it in your index.php file instead of the php.ini file.

if( ! ini_get('date.timezone') )

{

    date_default_timezone_set('GMT');

}

最新提问 1月 26, 2015 分类:php | 用户: forlong401 (7,050 分)

登录 或者 注册 后回答这个问题。

...