【问题标题】:error in php date function using codeigniter使用codeigniter的php日期函数中的错误
【发布时间】:2012-02-27 15:14:12
【问题描述】:
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 页面收到此错误。我使用 codeigniter 作为框架。这是我用来创建日期的代码:

$datestring = "%d/%m/%Y - %h:%i %a";
$time = time();

$data['curr_time'] = mdate($datestring, $time);

哪里出错了?

【问题讨论】:

  • 错误是没有阅读错误信息 - 它告诉你问题是什么以及如何解决它......

标签: php codeigniter date


【解决方案1】:

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

date_default_timezone_set('UTC');

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

date.timezone = "美国/安克雷奇"

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      相关资源
      最近更新 更多