Week numbers in JavaScript

To get the current ISO 8601 week number in JavaScript, use the following code snippet:

// Calculate ISO Week const d = new Date(); d.setHours(0,0,0,0); d.setDate(d.getDate() + 4 - (d.getDay()||7)); const yearStart = new Date(d.getFullYear(),0,1); const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1)/7); console.log(weekNo);

* Ensure your system or application regional settings are set to follow ISO 8601 standards (weeks start on Monday) if the output varies.

Free widgets for webmasters:

Free Analog Clock Widget | Free Digital Clock Widget | Free Text Clock Widget | Free Word Clock Widget | Free Countdown Widget