我正在尝试使用Moment.js显示下一个即将到来的星期四,但不确定为什么跳过中间日期。例如:代替显示:9月3日,10日,17日,24日,10月1日

而是显示9月3日,10日,24日,10月15日,11月12日,12月17日等...

这是我到目前为止的内容:

var date = moment();
var y = 3;
while (y<56) {
   var nextThursday = date.weekday(y).add(1,"days").format("dddd, MMM Do");
   var addValueThursday = nextThursday;
   var thurs = {"text": addValueThursday};
   console.log(addValueThursday);
   y+=7;
}

最佳答案

这是从本周开始我将如何查找星期四的下10个事件:

   var thursday = moment().startOf('week').add(4, 'days');

   for (var i=0; i<10; i++) {
     console.log(thursday.format("dddd, MMM Do"));
     thursday = thursday.add(1, 'week');
   }


console.log类似:

Thursday, Sep 3rd
Thursday, Sep 10th
Thursday, Sep 17th
Thursday, Sep 24th
Thursday, Oct 1st
Thursday, Oct 8th
Thursday, Oct 15th
Thursday, Oct 22nd
Thursday, Oct 29th
Thursday, Nov 5th


jsbin:https://jsbin.com/gojetisawu/1/edit?html,output

关于javascript - Moment.js无法正确显示所有日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32387281/

10-12 00:48