Get week of year in JavaScript like in PHP

后端 未结 19 1350
南方客
南方客 2020-11-22 02:38

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

19条回答
  •  醉酒成梦
    2020-11-22 03:05

    Not ISO-8601 week number but if the search engine pointed you here anyways.

    As said above but without a class:

    let now = new Date();
    let onejan = new Date(now.getFullYear(), 0, 1);
    let week = Math.ceil( (((now.getTime() - onejan.getTime()) / 86400000) + onejan.getDay() + 1) / 7 );
    

提交回复
热议问题