简体   繁体   中英

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

Like the title, i have problem with date(Ymd H:i:s); function with give wrong time. I have changed config.php file with add date_default_timezone_set('Asia/Singapore'); on top of the file and it is not fully working.

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

However it working if i add it at the method/function that use date function as example :

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

Can anyone explain why if i add date_default_timezone_set in config.php not working? I must add it as global cause too much code that use date function.

The case above similar to here but i already try that suggestion but not working : CodeIgniter date - wrong time

have you tried changing timezone in your php.ini ?

[Date]
date.timezone=Asia/Singapore

more reference here http://www.inmotionhosting.com/support/website/php/setting-the-timezone-for-php-in-the-phpini-file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM