Magento – How to change Magento timezone

magento-1.9timezone

I have used Magento 1.9 initially timezone was America/Los_Angeles in app/etc/config.xml file and set India/Calcutta timezone in

System -> Configuration -> General -> Locale Options ->Timezone

at that time Magento function Mage::getModel('core/date')->date('Y-m-d H:i:s') return correct date.
But order placed time was -5:30 to real time.

For set Asia/Calcutta timezone, I have changed app/etc/config.xml general->locale->timezone to Asia/Calcutta and in app/Mage.php I have changed UTC to Asia/Calcutta,

And it has changed the timezone in the backend, it means order placed time is correct as real-time but the function Mage::getModel('core/date')->date('Y-m-d H:i:s') return me +5:30 time to real time.

Is there any place where I missed to change?

Or Is there another method to change the timezone of the Magento store?

Best Answer

You can set timezone from Admin panel ,

Go to :

System => Configuration => General => Locale Options =>Timezone

enter image description here

AND

Change the default timezon in file app/Mage.php

date_default_timezone_set('UTC');

Replace above line with following

date_default_timezone_set('Asia/Calcutta');

AND

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';

Replace above line with following

const DEFAULT_TIMEZONE = 'Asia/Calcutta';

Note: If still it will not work. Dig in to following function in 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 helps

Related Topic