Created
July 20, 2021 18:31
-
-
Save elifiner/17dbc7ac706db5d452a4d848d90bedea to your computer and use it in GitHub Desktop.
Parse timezones with momentjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment-timezone'); | |
// parse time with timezone, convert to UTC, resulting object is in UTC | |
console.log(moment.utc('23:05+02:00', ['hh:mm a ZZ', 'HH:mmZZ'], true).format()); | |
// parse time with timezone, resulting object is in timezone specified in the time string | |
console.log(moment.parseZone('23:05+02:00', ['hh:mm a ZZ', 'HH:mmZZ'], true).format()); | |
// parse time with timezone, resulting object is converted to timezone specified in the timezone parameter | |
console.log(moment.tz('23:05+02:00', ['hh:mm a ZZ', 'HH:mmZZ'], 'America/Vancouver').format()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment