-
-
Save nncl/6c0705958c470ab113f0d8644c06b9f4 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