Skip to content

Instantly share code, notes, and snippets.

@simbathesailor
Created January 15, 2020 07:18
Show Gist options
  • Save simbathesailor/ca36a44dc49bb4dbf0a73e89955188df to your computer and use it in GitHub Desktop.
Save simbathesailor/ca36a44dc49bb4dbf0a73e89955188df to your computer and use it in GitHub Desktop.
getTimeZone.jsx
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