Created
April 23, 2018 10:49
-
-
Save ImanMh/bc34c79a932c307b5d6b63f6406fa597 to your computer and use it in GitHub Desktop.
Passing a day and a timezone offset and getting back local time.
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
const getLocalTime = (date, offset) => { | |
const utc = date.getTime() - (date.getTimezoneOffset() * 60000); | |
const corrected = new Date(utc + (3600000 * offset)); | |
return { | |
hours: corrected.getHours(), | |
minutes: corrected.getMinutes(), | |
}; | |
}; | |
// Tehran Local Time | |
getLocalTime(new Date(), '-4.5'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment