Skip to content

Instantly share code, notes, and snippets.

@197291
Created December 4, 2018 09:11
Show Gist options
  • Save 197291/52640c345baf652a2770581391c00078 to your computer and use it in GitHub Desktop.
Save 197291/52640c345baf652a2770581391c00078 to your computer and use it in GitHub Desktop.
Time with timeZone offset
calcTime(city: any, offset: any) {
// create Date object for current location
const d = new Date();
// convert to msec
// add local time zone offset
// get UTC time in msec
const utc = d.getTime() + (d.getTimezoneOffset() * 60000);
// create new Date object for different city
// using supplied offset
const nd = new Date(utc + (3600000 * offset));
// return time as a string
return nd.toLocaleString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment