如何删除“已过期”的Firebase项目或在Android Studio上超过当前日期? [英] How to delete firebase items that are "expired" or past the current date on Android Studio?

查看:138
本文介绍了如何删除“已过期”的Firebase项目或在Android Studio上超过当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在创建一个Android应用程序,列出校园周围发生的本地事件。每个事件都有用于存储标题,图像,类别,信息和日期的子项。我想知道删除当前日期的事件是最好的办法。日期格式为mm / dd / yy。我在Java中使用日期函数的经验并不多,可以使用一些建议。



以下是事件示例

一>。以下是源代码以供参考。最好的做法是将数据保存为 TIMESTAMP code>像这样 ServerValue.TIMESTAMP

  DatabaseReference ref = FirebaseDatabase.getInstance()。getReference(); 
Map map = new HashMap();
map.put(time,ServerValue.TIMESTAMP);
ref.child(yourNode)。updateChildren(map);

为了得到数据,我建议你使用这个方法:

  public static String getTimeDate(long timeStamp){
try {
DateFormat dateFormat = getDateTimeInstance();
日期netDate =(new Date(timeStamp));
return dateFormat.format(netDate);
} catch(Exception e){
returndate;






$ b

为了解决你的问题,你只需要取得日期从你的数据库,并与当前日期和时间进行比较。如果 TIMESTAMP 的值小于当前日期和时间,则可以删除该特定事件。



希望它有帮助。


Hello I am creating an Android app that lists local events happening around my campus. Each "event" has children for storing the title, image, category, info, and date. I was wondering what the best way would be to delete events that are past the current date. The date is formatted mm/dd/yy. I don't have much experience with using date functions in Java, and could use some advice.

Here is an example of an event. Here is the source code for reference. Any help is greatly appreciated.

解决方案

The best practice is to save your data as a TIMESTAMP like this ServerValue.TIMESTAMP.

DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
Map map = new HashMap();
map.put("time", ServerValue.TIMESTAMP);
ref.child("yourNode").updateChildren(map);

And to get the data back, i suggest you use this method:

public static String getTimeDate(long timeStamp){
    try{
        DateFormat dateFormat = getDateTimeInstance();
        Date netDate = (new Date(timeStamp));
        return dateFormat.format(netDate);
    } catch(Exception e) {
        return "date";
    }
}

To solve your problem, you only need get the date from your database and compare it with the current date and time. If the value of TIMESTAMP is less than the current date and time, than you can delete that particular event.

Hope it helps.

这篇关于如何删除“已过期”的Firebase项目或在Android Studio上超过当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆