Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
export function getTimezoneOffset(date, timeZone) {
const parts = new Intl.DateTimeFormat('en-US', {
hour12: false,
year: 'numeric', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric'
// The year string contains a comma, like "2016,", so we strip it using parseInt
const year = parseInt(parts[2], 10);
// The month is rendered in human readable terms, which are betweeen 1-12, but the API requires 0-11
const month = parts[0] - 1;
const day = parts[1];
const hour = parts[3];
const minute = parts[4];
const second = parts[5];
const t1 = Date.UTC(year, month, day, hour, minute, second);
const t2 = new Date(date).setMilliseconds(0);
return (t1 - t2) / 60000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment