我建议用
,通过使用
NSDate().timeIntervalSince1970 * 1000
Date().getTime();
let date = Int64(NSDate().timeIntervalSince1970 * 1000)
在你的
date
日期
下面是一个关于如何开始使用cron的优秀教程:
https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html
你的cron作业需要被编码进去
node.js
会像这样:
// example cron job after setting everything up in the tutorial
exports.hourly_job =
functions.pubsub.topic('hourly-tick').onPublish((event) => {
// get current date and time
var currentDate = new Date();
console.log("Hourly Deletion Ran at: " + currentDate);
var currentNumMilliseconds = currentDate.getTime();
// remove a days worth of time
var oneDayAgo = currentNumMilliseconds - (3 * 24 * 60 * 1000);
var cutoffDate = new Date(oneDayAgo);
console.log("Query start at date: " + oneDayAgo);
// the firebase database ref where your posts are stored
const ref = admin.database().ref('posts');
// query all posts more than a day old
ref.orderByChild('date').startAt(oneDayAgo).once('value').then(function (snapshot) {
// for each snapshot returned from the query that is older than one day, delete
snapshot.forEach(function(childSnapshot) {
var key = childSnapshot.key;
var postObject = childSnapshot.val();
ref.child('key').remove();
});
});
});