簡體   English   中英

日期函數在CodeIgniter和date_default_timezone_set('Asia / Singapore')中導致錯誤的時間; 在配置文件中不起作用

[英]Date function result wrong time in CodeIgniter and date_default_timezone_set('Asia/Singapore'); in Config file not working

像標題一樣,我對日期有疑問(Ymd H:i:s); 功能給錯時間。 我更改了config.php文件,添加了date_default_timezone_set('Asia / Singapore'); 位於文件頂部,並且無法完全正常工作。

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
date_default_timezone_set('Asia/Singapore');

但是,如果我在使用日期函數作為示例的方法/函數中添加它,它將起作用:

function giveMyDate(){ 
date_default_timezone_set('Asia/Singapore'); 
echo(date('Y-m-d H:i:s')); 
}

誰能解釋為什么我在config.php中添加date_default_timezone_set無法正常工作? 我必須將其添加為全局原因,因為使用日期函數的代碼過多。

上面的情況類似於這里,但我已經嘗試了該建議但不起作用: CodeIgniter日期-錯誤的時間

您是否嘗試過更改 php.ini 時區

[Date]
date.timezone=Asia/Singapore

此處提供更多參考http://www.inmotionhosting.com/support/website/php/setting-the-timezone-for-php-in-the-phpini-file

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM