I am trying to get the list of all the available timezones using moment-timezone in node js like this -
var moment = require('moment-timezone'); var timeZones = moment.tz.names(); console.log(timeZones);
I am getting the timezones in this format -
'Europe/Mariehamn', 'Europe/Minsk', 'Europe/Monaco', 'Europe/Moscow', 'Europe/Nicosia', 'Europe/Oslo', 'Europe/Paris', 'Europe/Podgorica', 'Europe/Prague', 'Europe/Riga', 'Europe/Rome',
But I want to get the timezones in this format -
(GMT +01:00) Africa/Brazzaville (GMT +01:00) Africa/Casablanca (GMT +01:00) Africa/Douala (GMT +01:00) Africa/El_Aaiun (GMT +01:00) Africa/Kinshasa (GMT +01:00) Africa/Lagos (GMT +01:00) Africa/Libreville (GMT +01:00) Africa/Luanda (GMT +01:00) Africa/Malabo (GMT +01:00) Africa/Ndjamena (GMT +01:00) Africa/Niamey
How do I get ?
var result = moment(someDate). format("MM/DD/YYYY HH:mm A Z");
You can use moment.tz() to get timezone full name. It will return undefined if timezone is not set.
Use Typescript @types packages and import it via import * as moment from 'moment-timezone'; You can use all moment methods and member vars as moment-timezone exports them. Show activity on this post. Show activity on this post. Show activity on this post.
utc(Date); By default, moment parses and displays in local time. If you want to parse or display a moment in UTC, you can use moment.
There is no straight way of getting in the format you want, directly from moment-timezone
.
Try like below.
var moment = require('moment-timezone'); var timeZones = moment.tz.names(); var offsetTmz=[]; for(var i in timeZones) { offsetTmz.push(" (GMT"+moment.tz(timeZones[i]).format('Z')+") " + timeZones[i]); }
Now, offsetTmz
is an array of strings in the format you want.
This is how I am using it.
Hope this will help you.
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