[英]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); 像标题一样,我对日期有疑问(Ymd H:i:s); function with give wrong time.
功能给错时间。 I have changed config.php file with add date_default_timezone_set('Asia/Singapore');
我更改了config.php文件,添加了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? 谁能解释为什么我在config.php中添加date_default_timezone_set无法正常工作? 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 上面的情况类似于这里,但我已经尝试了该建议但不起作用: CodeIgniter日期-错误的时间
have you tried changing timezone in your php.ini
? 您是否尝试过更改
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 此处提供更多参考http://www.inmotionhosting.com/support/website/php/setting-the-timezone-for-php-in-the-phpini-file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.