Created
November 30, 2022 14:41
-
-
Save kawanet/3bfa725e28f628b1962c9a41a1d74930 to your computer and use it in GitHub Desktop.
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 getTimezoneOffset = (timeZone, dt) => new Intl.DateTimeFormat("en-US", {timeZoneName: "longOffset", timeZone}).formatToParts(dt).find(v => v.type === "timeZoneName")?.value; | |
getTimezoneOffset("America/New_York", new Date()); // => "GMT-05:00" | |
getTimezoneOffset("America/New_York"); // => "GMT-05:00" | |
getTimezoneOffset("invalid"); // => Uncaught RangeError: Invalid time zone specified: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment