Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the time zone in CakePHP?

Tags:

cakephp

How can I change the time zone in CakePHP? My application uses the Indian time zone but it is hosted on a US server which takes a US time zone. Can anyone tell me how I can change the time zone?

like image 229
Dilip Godhani Avatar asked Mar 12 '10 09:03

Dilip Godhani


People also ask

How to set time zone in CakePHP?

An easy way to manage the time is to save all dates and times as GMT+0 or UTC. Uncomment the line date_default_timezone_set('UTC'); in config/bootstrap. php to ensure your application's time zone is set to GMT+0.

How can I get current date and time in cakephp?

use Cake\I18n\Time; // Create from a string datetime. $time = Time::createFromFormat( 'Y-m-d H:i:s', $datetime, 'America/New_York' ); // Create from a timestamp $time = Time::createFromTimestamp($ts); // Get the current time.


2 Answers

You can set the time zone in /app/config/core.php:

date_default_timezone_set('YourTimeZone')    //php5.3 is required

edit: try add this in your app/config/bootstrap.php

putenv('TZ=YourTimeZone');
like image 139
Young Avatar answered Sep 22 '22 22:09

Young


Set timezone in app/config/core.php

Configure::write('Config.timezone', 'Europe/Paris')
like image 40
KS Rajput Avatar answered Sep 24 '22 22:09

KS Rajput