Javascript日期+15天

时间:2017-11-01 20:48:32

标签: javascript date

我希望这一天是25天后,它需要与正常的工作日测量值相对应。周六,周日和节假日需要删除。我尝试过使用Google表格和javascript:

这就是我所拥有的。

function Calendar() {
  var now = new Date();
  var year = now.getFullYear();
  var month = new Array();
month[0] = "01";  
month[1] = "02";
month[2] = "03";
month[3] = "04";
month[4] = "05";
month[5] = "06";  
month[6] = "07";
month[7] = "08";
month[8] = "09";
month[9] = "10";
month[10] = "11";
month[11] = "12";  
  var monthnum = month[now.getMonth()];
  var weekday = new Array();
  weekday[0] = "Sunday";
  weekday[1] = "Monday";
  weekday[2] = "Tuesday";
  weekday[3] = "Wednesday";
  weekday[4] = "Thursday";
  weekday[5] = "Friday";
  weekday[6] = "Saturday";

  var day = weekday[now.getDay()];

  var date = now.getDate();

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Schedule");
  var last = sheet.getLastRow();
  var destination = sheet.getRange(last, 1);
  var format = sheet.getRange(10, 1, 1, 7);
  var insertdate = sheet.getRange(last, 2);
  var insertday = sheet.getRange(last, 1)



  sheet.insertRowAfter(last);
  sheet.deleteRow(7)
  insertdate.setValue(monthnum + "/" + date + "/" + year);
  insertday.setValue(day)


  Logger.log(monthnum + "/" + date + "/" + year + " " + day)
}

1 个答案:

答案 0 :(得分:-1)

有很多方法可以做到,但很容易就是:86400000是一天

86400000= 24 Hours * 60 Min * 60 Seconds * 1000 Milliseconds

以下是一个可以帮助您的示例:



var first = new Date();
var last = new Date(new Date(first).getTime() + (86400000 * 25));
var now = new Date(); now.setDate(now.getDate() + 25);
console.log(first);
console.log(last);
console.log(now);