I will provide two dates, as a range e.g 5th Oct 2016 to 5th December 2016, And 5th Oct was Wednesday so return me all the Wednesdays till 5th December 2016.
我将提供两个日期,例如2016年10月5日至2016年12月5日的范围,10月5日是星期三,所以在星期三到2016年12月5日返回我。
How can this be possible using Javascript or AngularJS ?
如何使用Javascript或AngularJS实现这一目标?
1 个解决方案
#1
1
Though not completely sure what you want to do, I think this will give you enough to work with:
虽然不完全确定你想做什么,但我认为这会给你足够的工作:
var startdate = new Date("2016-10-05");
var enddate = new Date("2016-12-05");
var wednesdays = [];
while (startdate <= enddate) {
wednesdays.push(startdate);
// add a week
startdate = new Date(startdate.setDate(startdate.getDate() + 7));
}
console.log(wednesdays);
#1
1
Though not completely sure what you want to do, I think this will give you enough to work with:
虽然不完全确定你想做什么,但我认为这会给你足够的工作:
var startdate = new Date("2016-10-05");
var enddate = new Date("2016-12-05");
var wednesdays = [];
while (startdate <= enddate) {
wednesdays.push(startdate);
// add a week
startdate = new Date(startdate.setDate(startdate.getDate() + 7));
}
console.log(wednesdays);