I need to create a select with the following values,
Eastern Standard Time (EST, GMT-5:00)
Central Standard Time (CST, GMT-6:00)
Mountain Standard Time (MST,GMT-7:00)
Phoenix Standard Time (PNT, GMT-7:00)
Pacific Standard Time (PST, GMT-8:00)
is there a way to do it through moment.js ?
var moment = require('moment-timezone'); moment().tz("America/Los_Angeles").format(); Note: By default, webpack bundles all moment-timezone data (in moment-timezone 0.5.25, that's over 900 KBs minified).
You can use moment.tz() to get timezone full name. It will return undefined if timezone is not set. Beside, you can use moment. format('zz') to get short timezone name.
For example, if you parse the string '2020/01/02' and then call the moment#tz() method, you're telling moment to parse the string in the locale time, and then convert the date to a given IANA timezone. // '20200101 21:00 PST' moment('2020/01/02', 'YYYY/MM/DD').
Moment-Timezone is an add-on for Moment. js. Both are considered legacy projects, now in maintenance mode. In most cases, you should choose a different library. For more details and recommendations, please see Project Status in the Moment docs.
moment.js
has timezone support via moment-timezone, so if you load the full set of timezones, you can filter for the time zones you care about by iterating through moment.tz.names()
, and then calling format("z, Z")
to get the string you want.
> moment.tz("America/Los_Angeles").format("z, Z")
"PDT, -07:00"
> moment.tz("2016-01-01", "America/Los_Angeles").format("z, Z")
"PST, -08:00"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With