Created
August 15, 2016 13:42
-
-
Save dtomasi/edc8d67a540ff71fb2d7339f23163596 to your computer and use it in GitHub Desktop.
Get Week of Year in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date.prototype.getWeek = function() { | |
var jan4th = new Date(this.getFullYear(),0,4); | |
return Math.ceil((((this - jan4th) / 86400000) + jan4th.getDay()+1)/7); | |
} | |
var now = new Date(); | |
var weekNumber = now.getWeek(); | |
console.log(weekNumber); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems like it's not correct,
Sunday 3 January 2010 is written as "2009-W53-7" but with this it shows that the weeknumber is "1"
Monday 29 December 2008 is written "2009-W01-1" same here, the week should be 01 and it shows 53