我需要向 admin.database.ServerValue.TIMESTAMP 添加时间,然后检索它。但是当我尝试添加额外的时间时,ServerValue.TIMESTAMP
我收到错误:
getTime 不是一个函数
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const ten_secs = 10 * 1000; // 10 seconds
const daily_secs = 24 * 60 * 60 * 1000; // 24 hrs
const weekly_secs = 168 * 60 * 60 * 1000; // 1 week
exports.update = functions.https.onRequest((request, response) => {
const currentTimeStamp = admin.database.ServerValue.TIMESTAMP;
const updatedSecs = new Date(currentTimeStamp.getTime() + ten_secs); // should be saved in the db as milliseconds for later retrieve and calculations
const updatedDay = new Date(currentTimeStamp.getTime() + daily_secs); // should be saved in the db as milliseconds for later retrieve and calculations
const updatedWeek = new Date(currentTimeStamp.getTime() + weekly_secs); // should be saved in the db as milliseconds for later retrieve and calculations
console.log("updatedSecs: " + updatedSecs + " | updatedDay: " + updatedDay + " | updatedWeek: " + updatedWeek);
const ref = admin.database().ref('schedule').child("scheduleId_123").child("my_uid")
ref.once('value', snapshot => {
if (!snapshot.exists()) {
return ref.set({ "updatedSecs": updatedSecs, "updatedDay": updatedDay, "updatedWeek": updatedWeek });
} else {
const retrieved_updatedSecs = snapshot.child("updatedSecs").val();
const retrieved_updatedDay = snapshot.child("updatedDay").val();
const retrieved_updatedWeek = snapshot.child("updatedWeek").val();
const currentTime = Date.now();
// do some calculations with the above values and currentTime.
}
});
}
犯罪嫌疑人X
斯蒂芬大帝
largeQ
相关分类