Skip to content

Instantly share code, notes, and snippets.



Last active Dec 15, 2015
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment