Skip to content

Instantly share code, notes, and snippets.

@Serhioromano Serhioromano/calendar.js
Last active Dec 15, 2015

Embed
What would you like to do?
How to number of week in a year with javascript. The best way is to prototype it into core Javascript Date class so you can use it later in any part of your code.
Date.prototype.getWeek = function() {
var first = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this.getTime() - first.getTime()) / 86400000) + first.getDay() + 1) / 7);
}
var date = new Date();
console.log(date.getWeek());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.