刚刚意识到为什么我的网站现在显示所有日期时间变量为-1小时......我第一次使用Codeigniter!(之前没遇到过这个问题)
所以,我在我的主index.php文件中包含了以下代码
/*
|---------------------------------------------------------------
| DEFAULT TIMEZONE
|---------------------------------------------------------------
|
| Set the default timezone for date/time functions to use if
| none is set on the server.
|
*/
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
Run Code Online (Sandbox Code Playgroud)
但是,它仍然显示为-1小时,所以我假设我需要为MySQL设置某种默认设置...
我在我的模型中包含以下代码行:
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->db->query("SET time_zone='+0:00'");
}
Run Code Online (Sandbox Code Playgroud)
仍然没有区别......帮助!
我的代码是:
<h3><?=date('D, jS F @ g:ia', strtotime($row->datetime))?></h3>
Run Code Online (Sandbox Code Playgroud)
$ row-> datetime变量只不过是MySQL数据库中的DATETIME列值.视图中的回显变量总是比我数据库中的值小1小时...
我的型号代码是:
function coming_up()
{
$this->db->query("SET time_zone='+0:00'");
$query = $this->db->query('SELECT * FROM events1 WHERE datetime >= NOW() ORDER BY datetime …Run Code Online (Sandbox Code Playgroud)