-
-
Save rahulraghavankklm/51a4c16230d6adf4d89e473db7e012ec to your computer and use it in GitHub Desktop.
JavaScript Get week number.
This file contains hidden or 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 onejan = new Date(this.getFullYear(), 0, 1); | |
| return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7); | |
| }; | |
| var myDate = new Date("2001-02-02"); | |
| myDate.getWeek(); //=> 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment