Skip to content

Instantly share code, notes, and snippets.

@AmyShackles
Created September 15, 2020 14:19
Show Gist options
  • Select an option

  • Save AmyShackles/950002bbda46e112a282b0bbe699b5fa to your computer and use it in GitHub Desktop.

Select an option

Save AmyShackles/950002bbda46e112a282b0bbe699b5fa to your computer and use it in GitHub Desktop.
Return time in provided time zone using Intl
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