Skip to content

Instantly share code, notes, and snippets.

@nncl
Forked from dtomasi/getWeek.js
Created October 12, 2017 22:30
Show Gist options
  • Save nncl/6c0705958c470ab113f0d8644c06b9f4 to your computer and use it in GitHub Desktop.
Save nncl/6c0705958c470ab113f0d8644c06b9f4 to your computer and use it in GitHub Desktop.
Get Week of Year in Javascript
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