Created
April 15, 2021 16:55
-
-
Save segdeha/3d1b9100ee9c41fc13f6aeffe78eb9e5 to your computer and use it in GitHub Desktop.
Return the number of the week (e.g., 16 out of 52 weeks)
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
function getWeekNumber() { | |
const now = new Date() | |
const oneJan = new Date(now.getFullYear(), 0, 1) | |
const numDays = Math.floor((now - oneJan) / (24 * 60 * 60 * 1000)) | |
return Math.ceil(( now.getDay() + 1 + numDays) / 7) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment