How do I get timezones list using moment.js library?

First include moment-timezone with data and then you can use moment.tz.names();


var timeZones = moment.tz.names();

See http://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/


Beware that moment.js does not comes with moment-timezone.js by default, you have to get it.

bower install moment-timezone --save
npm install moment-timezone --save
Install-Package Moment.Timezone.js

Or Downlaod

Then you can require an array of timezones in this way:

var timezones = moment.tz.names();

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.

var currentUserTimezone = moment.tz.guess();

Also, you can get abbreviation of timezones if you need them, in case you have to provide and array of abbreviations of timezones:

moment.tz('America/Los_Angeles').format('z') //PDT

moment-timezone.js full documentation


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:

<script src="/javascripts/modules/moment/moment-with-langs.min.js"></script>
<script src="/javascripts/modules/moment/moment-timezone.min.js"></script>
<script src="/javascripts/modules/moment/moment-timezone-data.js"></script>

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.