← Back to the tool

ISO Week Number in JavaScript

Updated: May 2026

JavaScript has no built-in ISO week method, but the algorithm is straightforward. The key is to work in UTC to avoid timezone-induced day shifts, and to treat the ISO year as independent from the calendar year for dates near year boundaries.

Verify week numbers online

Free · No upload · 100% in-browser

Core algorithm — date to ISO week

The standard approach: shift the date to the nearest Thursday (the anchor day of the ISO week), then count how many complete weeks have passed since the start of that Thursday's year.

function getISOWeek(date) { const d = new Date(Date.UTC( date.getFullYear(), date.getMonth(), date.getDate() )); const day = d.getUTCDay() || 7; // 1=Mon, 7=Sun d.setUTCDate(d.getUTCDate() + 4 - day); // shift to Thursday const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)); const week = Math.ceil((((d - yearStart) / 86400000) + 1) / 7); return { week, year: d.getUTCFullYear() }; }

The function returns both week and year. Always use the returned year, not date.getFullYear(). For a date like December 31, 2018, the ISO year is 2019 even though the calendar year is 2018.

Why use UTC methods?

JavaScript's local-time methods (getDay(), getDate(), etc.) apply the browser's timezone offset. In a UTC+12 timezone, a UTC midnight boundary becomes noon the previous day locally. This can push a date one day backward, landing it in the wrong ISO week. Using Date.UTC() and the getUTC* family eliminates this risk — dates are treated as timezone-neutral day values.

ISO week to Monday date

To find the Monday of a given ISO year and week:

function isoWeekMonday(isoYear, isoWeek) { const jan4 = new Date(Date.UTC(isoYear, 0, 4)); const jan4Day = jan4.getUTCDay() || 7; const weekOneMonday = new Date(jan4); weekOneMonday.setUTCDate(jan4.getUTCDate() - (jan4Day - 1)); const monday = new Date(weekOneMonday); monday.setUTCDate(weekOneMonday.getUTCDate() + (isoWeek - 1) * 7); return monday; }

January 4 is always in ISO week 1. The Monday of the week that contains January 4 is the Monday of week 1. From there, adding multiples of 7 days reaches any target week's Monday.

Using Intl.DateTimeFormat (modern approach)

Modern browsers support locale-aware week formatting via Intl.DateTimeFormat with the weekInfo option, but ISO week number as a format field is not yet standardized. A more reliable modern approach uses Temporal (TC39 Temporal proposal, available in some environments):

// Temporal API (requires polyfill in most browsers as of 2026) const d = Temporal.PlainDate.from('2026-05-28'); console.log(d.weekOfYear); // 22 console.log(d.yearOfWeek); // 2026

Until Temporal is universally available, the UTC-based manual algorithm above is the safest cross-browser solution without adding a dependency like date-fns or Luxon.

Counting ISO weeks in a year

A year has 53 ISO weeks if and only if December 28 of that year falls in week 53:

function isoWeeksInYear(year) { return getISOWeek(new Date(year, 11, 28)).week; // 52 or 53 }