gpt4 book ai didi

javascript - 计算日期数组

转载 作者:行者123 更新时间:2023-11-28 17:49:01 25 4
gpt4 key购买 nike

我正在尝试转换日期数组:

['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);

关于javascript - 计算日期数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46014046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com