Created
December 4, 2018 09:11
-
-
Save 197291/52640c345baf652a2770581391c00078 to your computer and use it in GitHub Desktop.
Time with timeZone offset
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
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