【问题标题】:CodeIgniter date - wrong timeCodeIgniter 日期 - 错误的时间
【发布时间】:2015-06-19 23:05:00
【问题描述】:

我正在使用:

date("d-m-Y h:i:s")

在我的控制器中,但时间比实际时间晚。 例如,现在在我的国家是 01:02,日期返回 20-06-2015 01:06:38。

如何解决?

【问题讨论】:

  • 所以你的时间少了几分钟?如果是这样,请调整您的服务器机器上的时间
  • @Mateusz Ji 尝试添加 config.php 就像我的回答说对我有用。

标签: codeigniter date time


【解决方案1】:

第一步: 转到config/config.php 并写下

//specify your region 
date_default_timezone_set('Europe/Warsaw');

第二步:现在你可以利用你的时间了

date("d-m-Y h:i:s") //for 21/12/2010 20:12:00
date("h:i:s") //for 12:12:11 time only 

【讨论】:

    【解决方案2】:

    将时区放在base_url上方的config.php文件顶部

    date_default_timezone_set('Europe/Warsaw');

    然后刷新服务器

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    date_default_timezone_set('Europe/Warsaw');
    
    /*
    |--------------------------------------------------------------------------
    | Base Site URL
    |--------------------------------------------------------------------------
    |
    | URL to your CodeIgniter root. Typically this will be your base URL,
    | WITH a trailing slash:
    |
    |   http://example.com/
    |
    | If this is not set then CodeIgniter will try guess the protocol, domain
    | and path to your installation. However, you should always configure this
    | explicitly and never rely on auto-guessing, especially in production
    | environments.
    |
    */
    $config['base_url'] = 'http://localhost/project/';
    

    【讨论】:

      【解决方案3】:

      如果您可以将配置文件中的挂钩设置从 TRUE 更改为 FALSE,这应该有助于解决您的问题。

      除非您非常需要启用挂钩,否则这种方式应该很好。

      $config['enable_hooks'] = TRUE;
      

      改为:

      $config['enable_hooks'] = FALSE;
      

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2018-01-28
        • 2018-05-31
        • 2012-04-28
        • 1970-01-01
        • 2012-01-11
        • 2016-09-16
        • 2013-09-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多