Skip to content

Instantly share code, notes, and snippets.

@ypetya
Created June 27, 2019 12:57
Show Gist options
  • Save ypetya/781619a8c26bb7332d472114c831d925 to your computer and use it in GitHub Desktop.
Save ypetya/781619a8c26bb7332d472114c831d925 to your computer and use it in GitHub Desktop.
Time zone in js
/**
* @return json object with converted time parts
* */
toTimeZone(utcDate, timeZone) {
return new Intl.DateTimeFormat('default', {
timeZone,
hour: 'numeric', minute: 'numeric', year: 'numeric', month: 'numeric', day: 'numeric', hour12: false
})
.formatToParts(utcDate).reduce((acc, curr) => ({...acc, [curr.type]: curr.value}), {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment