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?
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.
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.
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');
Set timezone in app/config/core.php
Configure::write('Config.timezone', 'Europe/Paris')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With