I need to make a <select> list of all actual world timezones. How do I get an array with timezones list?
相关问题
- Convert AJAX date to Javascript date for use with
- How to validate date with Moment.js to a specified
- Angular Material 10 range datepicker and moment.js
- Moment.js : change the default humanize() behavior
- How to check system's time format in chrome -
相关文章
- Check if times overlap using moment?
- Mustache doesn't Evaluate {{}} inside function
- How to Perform Timing Subtraction using Moment Js?
- Need to format time zone offset using moment js
- Moment.js dynamically update time in seconds
- Moment.js sets dates to 1 day behind
- How to shorten the timezone name list got from mom
- gulp typescript throws error TS2300: Duplicate ide
For timezone, you should manually add timezone JS file made by yourself.
In this page, you can pick the zones up and generate a file to be loaded after you load
moment.js
first off.You should have something like this, take a look:
The JS
moment-timezone-data.js
is the custom list of the timezones.However, so far I know, MomentJS does not return for you a list of all timezones, because timezone can be changed as well. If you need to populate a
select
tag, I suggest you parse the timezone list manually from the link above.First include
moment-timezone
with data and then you can usemoment.tz.names();
There are 378 timezones. A timezone is any combination of rules about time, including DST, that was in effect for any period of time, in any locale, no matter how tiny--such as an individual town in Indiana that decided to go off daylight savings time for two years in the 1940s. Or, to take a more recent example, the North Korean time zone, which was just moved up by 30 minutes. Or a dozen time zones just for Antarctica.
I doubt if you want to show all these timezones in your pulldown. You need to choose the most common 50-100 or so. You can either do that by yourself, or you can copy the list from some site like Google. You probably want to choose at least one timezone from each of the 24 offsets, so no matter where a person is, they can find one that sort of matches.
Include moment-timezone.js from cdn.
Now, use
moment.tz._names
to get the timezones as an object. The methodmoment.tz.names()
also gives the timezones as an array, but its slower.Versions prior to 0.4.0, don't have the
moment.tz._names
object hencemoment.tz.names()
method must be used.Beware that moment.js does not comes with moment-timezone.js by default, you have to get it.
Or Downlaod
Then you can require an array of timezones in this way:
Another useful trick is that you can set(guess) the current user timezone, so you don't have to make the user look for his timezone in a huge list, or you can set a timezone by default and then let the user change it if he needs it.
Also, you can get abbreviation of timezones if you need them, in case you have to provide and array of abbreviations of timezones:
moment-timezone.js full documentation
See http://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/