如何在Magento 2中将所有时区列表作为数组获取 [英] How to get all time zones lists as array in Magento 2

查看:95
本文介绍了如何在Magento 2中将所有时区列表作为数组获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在自定义管理模块中添加一个表单字段,使用户可以选择时区.那么如何获取时区列表呢?

I have to add one form field in custom admin module that enables the users to select the timezone. So how to get the timezone lists?

此代码段在Magento 1中提供了时区列表.但是如何在Magento 2中获得相同的东西?

This code snippet gives timezones list in Magento 1. But how to get same thing in Magento 2?

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

推荐答案

您应像这样使用\Magento\Config\Model\Config\Source\Locale\Timezone::toOptionArray():

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

然后在您的代码中:

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

这篇关于如何在Magento 2中将所有时区列表作为数组获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆