【发布时间】:2021-11-05 04:09:38
【问题描述】:
这就是函数(我感觉几个小时前我做了同样的事情,结果是我所期望的)
function errorFunction() {
let master = []
let a = [1,2] //a simple array to loop over
a.forEach(function(b) {
let theDate = Date.today() // 8th Sep 2021
let i = 0
while (i<2) {
theDate = Date.parse(theDate).addDays(1)
Logger.log(theDate) // dates are alternating between 9th and 10th september
master.push([b,i,theDate])
i = i+1
}
})
Logger.log(master) // all dates are 10th september
}
代码将 9 月 9 日和 9 月 10 日推送到数组。但是数组的输出只有9月10日。
我的期望:
[
[1.0, 0.0, Fri Sep 9 00:00:00 GMT+05:30 2021],
[1.0, 1.0, Fri Sep 10 00:00:00 GMT+05:30 2021],
[2.0, 0.0, Fri Sep 9 00:00:00 GMT+05:30 2021],
[2.0, 1.0, Fri Sep 10 00:00:00 GMT+05:30 2021]
]
我得到的输出:
[
[1.0, 0.0, Fri Sep 10 00:00:00 GMT+05:30 2021],
[1.0, 1.0, Fri Sep 10 00:00:00 GMT+05:30 2021],
[2.0, 0.0, Fri Sep 10 00:00:00 GMT+05:30 2021],
[2.0, 1.0, Fri Sep 10 00:00:00 GMT+05:30 2021]
]
我正在使用最新版本的 DateJs 库。
【问题讨论】:
-
请提供更多详细信息。
a和b是什么?什么是Date.today(),9 月 9 日或 10 日? -
@DmitryKostyuk 我已经更新了问题。
标签: javascript google-apps-script datejs