Created
September 15, 2020 14:19
-
-
Save AmyShackles/950002bbda46e112a282b0bbe699b5fa to your computer and use it in GitHub Desktop.
Return time in provided time zone using Intl
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
| function getTimeZone(timeZone) { | |
| if (timeZone) { | |
| let options = { | |
| timeZone, | |
| year: "numeric", | |
| month: "numeric", | |
| day: "numeric", | |
| hour: "numeric", | |
| minute: "numeric", | |
| second: "numeric" | |
| }, | |
| toTimeZone = new Intl.DateTimeFormat([], options); | |
| return new Date(toTimeZone.format(new Date())); | |
| } else { | |
| return new Date(Date.now()); | |
| } | |
| } | |
| export { getTimeZone } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment