6

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?

4 Answers 4

9

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

3
  • I have already set India Standard time (Asia/Calcutta) in Timezone. Commented Mar 10, 2016 at 6:31
  • @VinayaMaheshwari Check updated answer Commented Mar 10, 2016 at 6:38
  • Hello @Rohit, this is not working for me. Commented Mar 10, 2016 at 6:44
7

you have to set your timezone manually

first go to

app/etc/config.xml add your time zone here

<general>
            <locale>
                <code>en_US</code>
                <timezone>Asia/Calcutta</timezone>
            </locale>
        </general>

second go to app/Mage.php

on line 768

change this line too

date_default_timezone_set('UTC');

to your timezone

date_default_timezone_set('Asia/Calcutta');

9
  • Hello @Qaisar Satti, please read my question, both changes I have already made but the problem is Mage::getModel('core/date')->date('Y-m-d H:i:s') function return me incorrect time +5:30 to real time. Is there any place where I missed to change? Commented Mar 10, 2016 at 6:34
  • did you check with new order time is correct? Commented Mar 10, 2016 at 6:35
  • Yes I have said in my question that order place time is correct. Commented Mar 10, 2016 at 6:37
  • did you refresh the cache? delete var/cache folder because for after these it good to go Commented Mar 10, 2016 at 6:39
  • Yes I refresh cache from backend and also remove from var/cache folder. Commented Mar 10, 2016 at 6:46
0

Your locale settings are defined in the configuration under System => Configuration => General => Locale Options =>Timezone, and can be set per website scope.

You can quickly get/change in your core_config_data table (SELECT * FROM core_config_data WHERE path = 'general/locale/timezone';).

You might use Mage::getModel('core/date') for getting current time and date.


Getting formatted date based on locale settings:

echo Mage::getModel('core/date')->date('d/m/Y H:i:s');
# return 22/10/2017 23:30:21

echo Mage::getModel('core/date')->timestamp();
# return current timestamp

echo date('d/m/Y H:i:s', Mage::getSingleton('core/date')->gmtTimestamp());
# returo current date in GMT timezone, doesn't matter your locale settings

enter image description here See app/code/core/Mage/Core/Model/Date.php for a complete list of methods available.

My suggestion is: try to convert everything to GMT using this model's GMT methods, and stop worrying about php.ini, magento XML, and so on.

0

In Magento 2 you have to use Asia/Kolkata instead of Asia/Calcutta

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.