weekOfYear
Returns the zero-indexed week of the year that a date corresponds to.
- Use
new Date()andDate.prototype.getFullYear()to get the first day of the year as aDateobject. - Use
Date.prototype.setDate(),Date.prototype.getDate()andDate.prototype.getDay()along with the modulo (%) operator to get the first Monday of the year. - Subtract the first Monday of the year from the given
dateand divide with the number of milliseconds in a week. - Use
Math.round()to get the zero-indexed week of the year corresponding to the givendate. -0is returned if the givendateis before the first Monday of the year.