How do I get the current weeknumber of the year, like PHP\'s date(\'W\')
?
It should be the ISO-8601 week number of year, weeks starting
The code snippet which works pretty well for me is this one:
var yearStart = +new Date(d.getFullYear(), 0, 1);
var today = +new Date(d.getFullYear(),d.getMonth(),d.getDate());
var dayOfYear = ((today - yearStart + 1) / 86400000);
return Math.ceil(dayOfYear / 7).toString();
Note:
d
is my Date for which I want the current week number.
The +
converts the Dates into numbers (working with TypeScript).