3 回答

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
const endDate = snapData.val().startDate + snapData.val().duration*24*60*60*1000;
足以以毫秒為單位獲取所需的日期(如果startDate
以毫秒為單位)
否則如果startDate
是日期字符串,
const endDate = (new Date(snapData.val().startDate)).getTime() + snapData.val().duration*24*60*60*1000;
假設(shè)您需要endDate
以毫秒為單位。

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
最后我得到了解決方案
exports.terminateStoreAd = functions.https.onRequest(async(req, res) => {
try {
const snapshot =await admin.database().ref("StoreAds").once("value");
const promises = [];
if (snapshot.exists()) {
snapshot.forEach(childSnapshot => {
const endDate=childSnapshot.val().startDate + childSnapshot.val().duration * 86400;
const today=Math.round(new Date().getTime()/1000);
if (endDate <= today) {
promises.push(
admin.database().ref("StoreAdsHistory").child(childSnapshot.key).set(childSnapshot.val()),
childSnapshot.ref.remove(),
res.send()
);
}
});
}
await Promise.all(promises);
}catch (error) {
}
});

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊
給定開始日期 2019-05-01 然后 5 天后是使用參數(shù)化版本創(chuàng)建新日期的簡單問題。
注意月份是零索引,所以五月,第 5 個(gè)月是索引 4。因?yàn)槲蚁胍?5 月 1 日之后的 5 天,所以我使用1+5作為日期:
const startDate = new Date(2019, 4, 1);
const endDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate()+5);
console.log(`Start Date: ${startDate}, End Date: ${endDate}`);
console.log(`Start Date: ${startDate.valueOf()}, End Date: ${endDate.valueOf()}`);
添加回答
舉報(bào)