Skip to content

Time handling with moment timezone

Megan Riel-Mehan edited this page Oct 23, 2019 · 3 revisions
  1. Convert local time to timestamp with offset
    th.dateObj is a unix timestamp in milliseconds
    tzString is a zone string like 'America/New_York'
moment(th.dateObj).tz(tzString).format()  
// example output: 2019-10-07T17:30:00-04:00
  1. Convert to local time if you know the zone name
event.zoneName = 'America/New_York'  
moment(event.timeStart).tz(event.zoneName).format('MMMM Do YYYY, h:mm a z')
  1. Convert to local time from date time stamp with offset but no timezone name. Note: without location information you can't get the actual time zone out because of daylight savings.
moment.parseZone(record.timeStart).format('ddd, MMM D YYYY h:mm a');

Clone this wiki locally