Moment.js get the week number based on a specific day (also past years)

后端 未结 2 1174
萌比男神i
萌比男神i 2020-12-29 18:01

How could I get from moment JS the week number from a date in the past only from a moment formatted object from a day selected?

2条回答
  •  醉梦人生
    2020-12-29 18:45

    You can also use format()

    Examples:

    moment().format('w') // as .week() like '1'
    moment().format('W') // as .isoWeek() like '1'
    moment().format('ww') // as .week() (2 digits) like '01'
    moment().format('WW') // as .isoWeek() (2 digits) like '01'
    

    ISO Week date: https://en.wikipedia.org/wiki/ISO_week_date

    More info: https://momentjs.com/docs/#week-year-week-and-weekday-tokens

提交回复
热议问题