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

后端 未结 10 1111
旧巷少年郎
旧巷少年郎 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 16:08

    Most of these answers do not address the OP's question. Andrejs Kuzmins' is the best, but I would improve on it a little more so the algorithm accounts for locale.

    var nextMoOrTh = moment().isoWeekday([1,4,4,4,8,8,8][moment().isoWeekday()-1]);
    

提交回复
热议问题