代码之家  ›  专栏  ›  技术社区  ›  Jaqueline

检查并比较Firebase Swift中消息的时间

  •  3
  • Jaqueline  · 技术社区  · 7 年前

    我要做的是我有一个用Swift制作的消息应用程序,我使用Firebase作为我的数据库。我想做的是像在Snapchat中一样,拥有消失消息的功能;不过,我不太清楚我该怎么做。我在数据库中的消息上有一个时间戳,但我不知道如何使用它。 This 我只是不知道它的确切代码。

    下面是我的数据库结构的图片。如果你需要更多的信息,请告诉我。谢谢你

    Here

    1 回复  |  直到 7 年前
        1
  •  0
  •   hackerman58888    7 年前

    我建议用 ,通过使用 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();
                });
    
            });
        });
    
    推荐文章