Find next instance of a given weekday (ie. Monday) with moment.js

后端 未结 10 1060
旧巷少年郎
旧巷少年郎 2020-12-02 15:36

I want to get the date of the next Monday or Thursday (or today if it is Mon or Thurs). As Moment.js works within the bounds of a Sunday - Saturday, I\'m having to work out

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 15:56

    IMHO more elegant way:

    var setDays = [ 1, 1, 4, 4, 4, 8, 8 ],
        nextDay = moment().day( setDays[moment().day()] );
    

提交回复
热议问题