使用代码点火器的 PHP 日期函数中出错


error in php date function using codeigniter

A PHP Error was encountered
Severity: Warning
Message: date() [function.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 'Europe/Berlin' for 'CET/1.0/no DST' instead

我从我的 php 页面收到此错误。我使用代码点火器作为框架。这是我用来创建日期的代码:

$datestring = "%d/%m/%Y - %h:%i %a";
$time = time();
$data['curr_time'] = mdate($datestring, $time);

错误在哪里?

我猜你有php 5.3。无论如何,解决方案是通过在使用任何时间/日期函数之前将下一个代码添加到 php 文件中来定义 php 的时区:

date_default_timezone_set('UTC');

或者,一个更好的解决方案,编辑你的php.ini文件并添加:

date.时区 = "美国/安克雷奇">

America/Anchorage是时区,请使用列表中与您相关的时区:

http://nl3.php.net/manual/en/timezones.php

在 index.php 文件中使用以下代码

if( !ini_get('date.timezone') )
{
    date_default_timezone_set('America/New_York');
}