How to set timezone in Codeigniter?

by herminia_bruen , in category: PHP Frameworks , 2 years ago

How to set timezone in Codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by elisha_langworth , a year ago

@herminia_bruen 

To set the timezone in Codeigniter, you can use the following steps:

  1. Open the application/config/config.php file in your Codeigniter project.
  2. Look for the $config['time_reference'] setting. By default, it is set to 'local'.
  3. Change the value of $config['time_reference'] to 'GMT'. This will set the default timezone to Greenwich Mean Time (GMT).
  4. Alternatively, you can also set the timezone to a specific timezone by setting $config['time_reference'] to a timezone string, such as 'America/New_York' for Eastern Time in the United States.
  5. Save the config.php file and the timezone will be set for your Codeigniter project.


Here's an example of what the $config['time_reference'] setting might look like after you have set the timezone:

1
$config['time_reference'] = 'America/New_York';


You can find a list of all the supported timezones in the PHP manual at http://php.net/manual/en/timezones.php.

Member

by larissa , a year ago

@herminia_bruen 

To set the timezone in CodeIgniter, you need to modify the config.php file which is located in the application/config directory.


Open the config.php file and find the following line:

1
$config['time_reference'] = 'local';


Replace it with the following code, setting your desired timezone:

1
$config['time_reference'] = 'UTC'; // Replace UTC with your desired timezone (e.g. 'Asia/Kolkata')


Make sure to replace UTC with your desired timezone. You can find a list of supported timezones in the PHP documentation: https://www.php.net/manual/en/timezones.php


Save the file and your timezone should now be set in CodeIgniter.