How To Setup, Configure & Manage Time Zones In Magento

Lately many people asked us questions on how to manage & setup timezone for their Magento store and why Magento uses UTC (coordinated Universal Time). Now, you must be having few other sites running as per your timezone requirements so why your Magento powered store has to rely on UTC? Answer is simple, Magento is built to run on most of the platforms so if you run your store on cloud servers, the server default will be UTC unless specified otherwise. Magento sets script’s time relative to server time which finally gets converted to UTC. So each Magento store (database-wise) is synced to UTC which will automatically help with cross-server synchronization.

Setting Up Different Timezones For Different Stores In Magento

Most of the big stores run multiple stores to target different customers from different parts of the world. For an example your default store might be running on Pacific Timezone but what about Australia or UK customers? Magento has  a solution to this problem. You can setup timezones for each store you have by navigating to  Admin Panel => System => Configuration => General => Locale Options => Timezone you can set different timezones for different countries or as per your own custom requirements. Just keep in mind that Admin Panel will use your site’s default timezone so don’t get confused with multi store’s timezone and admin timezone. You can anytime change the admin timezone from here System => Configuration => General => Locale Options =>Timezone

Just edit app/code/core/Mage/Core/Model/Locale.php this file and see your current store’s settings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * Create Zend_Date object with date converted to store timezone and store Locale
 *
 * @param   mixed $store Information about store
 * @param   string|integer|Zend_Date|array|null $date date in UTC
 * @param   boolean $includeTime flag for including time to date
 * @return  Zend_Date
 */
public function storeDate($store=null, $date=null, $includeTime=false)
{
    $timezone = Mage::app()->getStore($store)->getConfig(self::XML_PATH_DEFAULT_TIMEZONE);
    $date = new Zend_Date($date, null, $this->getLocale());
    $date->setTimezone($timezone);
    if (!$includeTime) {
        $date->setHour(0)
            ->setMinute(0)
            ->setSecond(0);
    }
    return $date;
}

I would love to hear your experiences of setting up timezones in Magento. Please leave me a comment and let me know. Subscribe our RSS to receive latest Magento updates.

  • http://ricardomartins.info/ Ricardo Martins

    My problem is to show a new datetime column on admin sales order grid…
    At that screen the funcion above isn’t triggered to set my correct timezone, so that screen uses the default UTC, showing wrong time there. =/
     

  • Atilla Boz

    Hello,

    I have the following problem: I am making a website for ticket sales in Senegal with Magento – the products have special dates and you can search them with a calendar function. You click on a day on the calendar and then it shows you all events on that day.

    So here`s the problem: It does only work in Browsers that use english language. In any other browser language I get the error message: “Specified date is invalid.”

    Does anybody know what do I have to do so it works with all other Browser languages, too?

    Thank you in advance,
    Atillla