Skip to content

Instantly share code, notes, and snippets.

@elifiner
Created July 20, 2021 18:31
Show Gist options
  • Save elifiner/17dbc7ac706db5d452a4d848d90bedea to your computer and use it in GitHub Desktop.
Save elifiner/17dbc7ac706db5d452a4d848d90bedea to your computer and use it in GitHub Desktop.
Parse timezones with momentjs
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