Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override server time in config.php codeigniter

I want to know how to override server time , my server is in UK but my Client is in Singapore and he wants Singapore time. in php.ini date.timezone is Europe/London which i do not want to change. i want to handle from config.php i tried this in codeigniter config.php

$config['time_diff']= "+8";
$config['time_reference'] = 'gmt';
date_default_timezone_set('UTC');

i also even tried this

$config['time_reference'] = 'local';
date_default_timezone_set('Singapore');
like image 284
user2210959 Avatar asked May 03 '26 19:05

user2210959


2 Answers

Within 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');
like image 50
Narendrasingh Sisodia Avatar answered May 05 '26 10:05

Narendrasingh Sisodia


You have to use codeigniter date helper functions.

Go to application/config.php and set time_reference from local to your timezone.

$config['time_reference'] = 'Europe/London';

Now load date helper inside your controller

$this->load->helper('date');

echo now(); // it returns UNIX timestamp according to timezone set in config. 

you can also pass timezone as parameter in now() function.

echo now('America/Los_Angeles');  

References - system/helpers/date_helper.php https://www.codeigniter.com/user_guide/helpers/date_helper.html

like image 36
Always 18 Avatar answered May 05 '26 08:05

Always 18