Magento 2 Timezone List

In this article, you going to see how to get Magento 2 timezone list.we going to see this point in depth step by step.

If your looking for timezone list in an array then you are at right place.

You can get this with the use class called timezone.

We going to discuss regarding Magento timezone list in detail step by step.

Before moving to the point, you should know that how the timezone list is achieved in Magento 1.

In Magento 1, with help of below code snippet you can get list of timezone in an array.

So let’s check with this below code snippet.

$timezone = Mage::getModel('core/locale')->getOptionTimezones();

In above code snippet you see that get model using get option timezone method with the help of this you get timezone list.

And it is assign to a variable called timezone.

With the help of this variable you will get list of array of timezone but in case of Magento 1.

Now our main important next this how to get this timezone list in case of Magento.

Let’s start with the point getting Magento 2 timezone list

From the below code snippet come to understand in depth regarding how to get this in Magento 2.

The class which is mentioned above called “Timezone”.

The path for this class file : \Magento\Config\Model\Config\Source\Locale\Timezone

You can use like this as follow as.


Below is code snippet

 * @param \Magento\Config\Model\Config\Source\Locale\Timezone $timezone
public function __construct(
    \Magento\Config\Model\Config\Source\Locale\Timezone $timezone
) {
    $this->timezone = $timezone;

After that in your code add as below given.

$timezone = $this->timezone->toOptionArray();

Then from variable called timezone you will get list of array of timezone in case in Magento.

This list of array you can use any where such as html select tag to populate list of drop down timezone.

PSD to Magento 2 theme conversion tutorial

Conclusion :

Finally, we done with the point getting Magento 2 timezone list.

I hope you like this article and if you feel like we missed out on anything, please comment below.

Leave a Comment