我在他的迷你项目中帮助了一位朋友,此时我们站在以下情况:例如,医生告诉他的病人,截至今天你有X次咨询,每周三和周五,如何获得这些磋商的日期,假设今天,它可以是一周中的任何一天??? 感谢
答案 0 :(得分:0)
我不确定这是否是您想要的,但您可以实现这一点,例如,像这样。
//get current date
var date = new Date ()
//array with week-day names
var week_days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
];
//your initial variables
var consultations = ['Wednesday', 'Friday'];
var X = 5;
//loop through X + 1 weeks to find dates and count results
var count = 0
for (var i = 0; i < (X + 1) * 7; i++) {
//get name of date-day
var week_day = week_days[date.getDay ()];
//check if wanted
if (consultations.indexOf (week_day) != -1) {
//construct date and output
var day = date.getDate ();
var month = date.getMonth ();
var year = date.getFullYear ();
document.write (day + '.' + month + '.' + year);
document.write ('<br/>');
//increment count
count++;
//stop if count == X
if (count == X)
break;
}
//increment date
date.setDate (date.getDate () + 1);
}
&#13;