如何在 config.php codeigniter 中覆盖服务器时间
How to override server time in config.php codeigniter
我想知道如何覆盖服务器时间,
我的服务器在英国,但我的客户在新加坡,他想要新加坡时间。
在 php.ini date.timezone 中是 Europe/London,我不想更改。我想处理来自 config.php
我在 codeigniter config.php
中试过了
$config['time_diff']= "+8";
$config['time_reference'] = 'gmt';
date_default_timezone_set('UTC');
我也试过这个
$config['time_reference'] = 'local';
date_default_timezone_set('Singapore');
config.php
内
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
date_default_timezone_set('Asia/Singapore');
您必须使用 codeigniter 日期辅助函数。
转到 application/config.php 并将 time_reference 从本地设置为您的时区。
$config['time_reference'] = 'Europe/London';
现在在你的控制器中加载日期助手
$this->load->helper('date');
echo now(); // it returns UNIX timestamp according to timezone set in config.
您还可以在 now() 函数中将时区作为参数传递。
echo now('America/Los_Angeles');
参考文献 -
system/helpers/date_helper.php
https://www.codeigniter.com/user_guide/helpers/date_helper.html
我想知道如何覆盖服务器时间, 我的服务器在英国,但我的客户在新加坡,他想要新加坡时间。 在 php.ini date.timezone 中是 Europe/London,我不想更改。我想处理来自 config.php 我在 codeigniter config.php
中试过了$config['time_diff']= "+8";
$config['time_reference'] = 'gmt';
date_default_timezone_set('UTC');
我也试过这个
$config['time_reference'] = 'local';
date_default_timezone_set('Singapore');
config.php
内<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
date_default_timezone_set('Asia/Singapore');
您必须使用 codeigniter 日期辅助函数。
转到 application/config.php 并将 time_reference 从本地设置为您的时区。
$config['time_reference'] = 'Europe/London';
现在在你的控制器中加载日期助手
$this->load->helper('date');
echo now(); // it returns UNIX timestamp according to timezone set in config.
您还可以在 now() 函数中将时区作为参数传递。
echo now('America/Los_Angeles');
参考文献 - system/helpers/date_helper.php https://www.codeigniter.com/user_guide/helpers/date_helper.html