moment.js, how to get day of week number

前端 未结 5 744
臣服心动
臣服心动 2020-12-09 00:53

I have a moment date object, and want to get the selected day number (0-6) or (1-7).

I tried this, but it doesn\'t work

var aaa = moment(date).day();         


        
5条回答
  •  天命终不由人
    2020-12-09 01:08

    If you are specifically looking for the 1-7 approach...

    This is the ISO weekday number. moment.js has also taken this into account. Use isoWeekday()

    console.log(moment().isoWeekday()); // returns 1-7 where 1 is Monday and 7 is Sunday

    Seeing as I wrote this answer on a Tuesday, today this gives me a 2.

提交回复
热议问题