Magento Tutorials

How to Set Up and Configure Timezone in Magento

In Magento, sometimes the system returns incorrect time even when you have configured the correct timezone in your backend. To solve this issue completely, you must follow all of these steps below.

1. Set up timezone in your Magento backend

Log into your Magento backend, go to System > Configuration > General > Locale Options, and select your current timezone (we use Asia/Bangkok in this example)

magento timezone

2. Change the default timezone in app/Mage.php

Open file app/Mage.php. Find the line:

date_default_timezone_set('UTC');

and replace that with the timezone that you want, for example:

date_default_timezone_set('Asia/Bangkok');

3. Edit file Locale.php

Copy file app/code/core/Mage/Core/Model/Locale.php to app/code/local/Mage/Core/Model/Locale.php then find line 38:

const DEFAULT_TIMEZONE = 'UTC';

and replace that with the timezone that you want, for example:

const DEFAULT_TIMEZONE = 'Asia/Bangkok';

If it still doesn’t work, you have to go deeper in the following function in file app/code/local/Mage/Core/Model/Locale.php:

public function storeDate($store=null, $date=null, $includeTime=false, $format = null)
{
$timezone = Mage::app()->getStore($store)->getConfig(self::XML_PATH_DEFAULT_TIMEZONE);
$date = new Zend_Date($date, $format, $this->getLocale());
$date->setTimezone($timezone);
if (!$includeTime) {
$date->setHour(0)
->setMinute(0)
->setSecond(0);
}
return $date;
}

Hope this guide be useful for you!

See also:
How to Configure Search Settings in Magento
How to Configure a Content Delivery Network (CDN) in Magento

Dom

A knowledge craver who always strive to be wiser everyday.