如何缩短从moment.js获得的时区名单? [英] How to shorten the timezone name list got from moment.js?

查看:103
本文介绍了如何缩短从moment.js获得的时区名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用moment.js(我使用的方法是 moment.tz.names())来检索时区名称列表,该列表列举了全球500多个城市。长列表使用户无法获得所需的时区。问题是是否有办法减少列表的大小,这意味着将同一时区的城市组合在一起。

I am using moment.js ( the method I used is moment.tz.names()) to retrieve the timezone name list which enumerates over 500 cities across the world. The long list makes it not very efficient for the users to pick up the desired timezone. The question is whether there is a way to cut down on the size of the list, meaning group the cities in the same timezone offset together.

推荐答案

这是积压时间区的事情,在问题#227

This is something on the backlog for moment-timezone, in issue #227.

以下是我在那里提供的临时解决方法,将列表缩短为365区域标识符。

Below is the temporary workaround I provided there, which will shorten the list to 365 zone identifiers.

var names = Object.keys(moment.tz._zones)
    .map(function(k) { return moment.tz._zones[k].split('|')[0]; })
    .filter(function(z) { return z.indexOf('/') >= 0; })
    .sort();

这将从列表中删除链接和缩写区域。我们认识到这仍然不理想,并将在未来版本中对此进行改进。

This removes links and abbreviated zones from the list. We recognize this is still not ideal, and will improve upon this in a future release.

这篇关于如何缩短从moment.js获得的时区名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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