Skip to content

Instantly share code, notes, and snippets.

Last active November 21, 2016 22:03
What would you like to do?
Timezone support using Moment.js
// get the user's timezone
var tz =;'Timezone: ' + tz);
// returns: Timezone: Europe/London
// set the default user timezone;
// set custom timezone'America/Los_Angeles');
// convert date / time to local timezone, assumes original date/time is in UTC
moment.utc('2016-12-25 07:00').tz(tz).format('ddd, Do MMMM YYYY, h:mma');
// returns: Sun, 25th December 2016, 7:00am
// convert date/time to LA Time
moment.utc('2016-12-25 07:00').tz('America/Los_Angeles').format('ddd, Do MMMM YYYY, h:mma');
// returns: Sat, 24th December 2016, 11:00pm
// convert from LA time to London'2016-12-25 07:00', 'America/Los_Angeles').tz('Europe/London').format( 'ddd, Do MMMM YYYY, h:mma' );
// returns: Sun, 25th December 2016, 3:00pm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment