Created
January 15, 2020 07:18
-
-
Save simbathesailor/ca36a44dc49bb4dbf0a73e89955188df to your computer and use it in GitHub Desktop.
getTimeZone.jsx
This file contains 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 getTimeZoneText(utcString) { | |
try { | |
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; | |
if (Intl) { | |
const zoneDateObj = utcToZonedTime(utcString, timeZone); | |
const timeZoneString = formatTimeZone(zoneDateObj, 'zzzz', { timeZone }); | |
return timeZoneString | |
.split(' ') | |
.map(elem => { | |
return elem.slice(0, 1); | |
}) | |
.join(''); | |
} | |
} catch (e) { | |
console.warn(e); | |
return ''; | |
} | |
return ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment