本文介绍了计算日期数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ['1','2','3' ,'4','5'] 

转换为今日+1天的日期数组,今天+2等

我有:

  interval_dates = [] 
var intervals = rows [index + 1] [0] .split(',')
var now = new Date();
for(i in intervals){
// add a day
interval_dates.push(now.setDate(now.getDate()+ intervals [i]));
}
Logger.log(interval_dates);

我看到

  [1.505998326018E12,1.522500726018E12,1.546869126018E12,1.552654326018E12,1.564750326018E12],] 

我做错了什么?

解决方案

  var dateRange = []; ['1','2','3','4','5'] forEach(function(dayIncrement){var date = new Date(); date。 setDate(date.getDate()+ parseInt(dayIncrement)); dateRange.push(date);}); console.log(dateRange);  


I'm trying to convert an array of days:

['1','2','3','4','5']

to an array of dates which are today +1 day , today +2 etc

I have:

interval_dates = []
var intervals =  rows[index+1][0].split(',')
var now = new Date();
for (i in intervals){
  // add a day
  interval_dates.push(now.setDate(now.getDate() + intervals[i]));
}
    Logger.log(interval_dates);

I'm seeing

[1.505998326018E12, 1.522500726018E12, 1.546869126018E12, 1.552654326018E12, 1.564750326018E12], ]

what am I doing wrong?

解决方案

var dateRange = [];

['1','2','3','4','5'].forEach(function(dayIncrement) {
  var date = new Date();
  date.setDate(date.getDate() + parseInt(dayIncrement));
  dateRange.push(date);
});

console.log(dateRange);

这篇关于计算日期数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 04:05