Get week of year in JavaScript like in PHP

后端 未结 19 1348
南方客
南方客 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 02:56

    Jacob Wright's Date.format() library implements date formatting in the style of PHP's date() function and supports the ISO-8601 week number:

    new Date().format('W');
    

    It may be a bit overkill for just a week number, but it does support PHP style formatting and is quite handy if you'll be doing a lot of this.

提交回复
热议问题