Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取接下来8个星期六的日期(javascript)_Javascript_Date_Dayofweek_Getdate - Fatal编程技术网

获取接下来8个星期六的日期(javascript)

获取接下来8个星期六的日期(javascript),javascript,date,dayofweek,getdate,Javascript,Date,Dayofweek,Getdate,我能得到最近的星期六的日期- 需要帮助查找接下来七个星期六的日期。 多谢各位 function myFunction(x){ var now = new Date(); now.setDate(now.getDate() + (x+(7-now.getDay())) % 7); document.getElementById("1s").innerHTML = now.getDate() + ' of ' + now.getMonth() + 'th'; } 只需在

我能得到最近的星期六的日期-

需要帮助查找接下来七个星期六的日期。 多谢各位

function myFunction(x){
    var now = new Date();  
    now.setDate(now.getDate() + (x+(7-now.getDay())) % 7);
    document.getElementById("1s").innerHTML = now.getDate() + ' of ' + now.getMonth() + 'th';
}

只需在你得到的日期的基础上再加上7天,然后循环你想要的周数

function myFunction(x){

    var now = new Date();  

    now.setDate(now.getDate() + (x+(7-now.getDay())) % 7);
    document.getElementById("1s").innerHTML = now.getDate() + ' of ' + now.getMonth() + 'th';

    var newDate = now;   
    for (var i = 2; i <= 8; i++) {

      var numberOfDaysToAdd = 7;
        newDate.setDate(newDate.getDate() + numberOfDaysToAdd); 

      document.getElementById("" + i + "s").innerHTML = newDate.getDate() + ' of ' + newDate.getMonth() + 'th';
    }

}
函数myFunction(x){
var now=新日期();
now.setDate(now.getDate()+(x+(7-now.getDay())%7);
document.getElementById(“1s”).innerHTML=now.getDate()+'of'+now.getMonth()+'th';
var newDate=now;

对于(var i=2;一旦你找到了第一个星期六,我可能会在日期上加上7,得到第二个星期六?它可以给我每个月30-31天范围内的数字…这没关系;JavaScript会给你一个正确的日期对象。太好了!谢谢你John!