第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何將天數(shù)添加到時(shí)間戳?

如何將天數(shù)添加到時(shí)間戳?

開滿天機(jī) 2021-06-11 09:12:17
我有一個(gè)開始日期時(shí)間戳和一個(gè)持續(xù)時(shí)間(天數(shù)),我需要得到結(jié)束日期,我厭倦了這段代碼給出了錯(cuò)誤的結(jié)束日期時(shí)間戳exports.terminateStoreAd = functions.https.onRequest(async(req, res) => {        try {            const snapshot =await admin.database().ref("StoreAds").once("value");            if (snapshot.exists()) {                snapshot.forEach(snapData => {                    if (snapData.exists()) {                        const endDate=new Date(snapData.val().startDate).getTime()+(snapData.val().duration*24*60*60*1000);                        res.send(""+endDate);                    }                });                res.send("done")            }        } catch (error) {            console.log("terminateStoreAd error :" + error.message);         }    });我的開始日期是:1559449773持續(xù)時(shí)間:5結(jié)束日期:1991449773 :(提前致謝。
查看完整描述

3 回答

?
幕布斯7119047

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以毫秒為單位。


查看完整回答
反對 回復(fù) 2021-06-18
?
慕容森

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) {


}

});


查看完整回答
反對 回復(fù) 2021-06-18
?
慕慕森

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()}`);


查看完整回答
反對 回復(fù) 2021-06-18
  • 3 回答
  • 0 關(guān)注
  • 264 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號