Created
June 27, 2019 12:57
-
-
Save ypetya/781619a8c26bb7332d472114c831d925 to your computer and use it in GitHub Desktop.
Time zone in js
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
/** | |
* @return json object with converted time parts | |
* */ | |
toTimeZone(utcDate, timeZone) { | |
return new Intl.DateTimeFormat('default', { | |
timeZone, | |
hour: 'numeric', minute: 'numeric', year: 'numeric', month: 'numeric', day: 'numeric', hour12: false | |
}) | |
.formatToParts(utcDate).reduce((acc, curr) => ({...acc, [curr.type]: curr.value}), {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment