我正在处理一个以datamessages
格式收到timestamp
"yyyy/MM/dd kk:mm:ss"
的应用。这是JSON数据格式。
"NOT20170828132901" :
{
"code" : "Your order status has been updated to Rejected",
"date" : "2017/08/28 13:29:01",
"title" : "Order update SPB20170825095233542"
}
我想根据最新的时间戳对 NOTNUMBER 进行排序。我尝试使用limitToLast(i)
和limitToFirst(i)
,但仍然是。结果是升序。我希望日期戳以降序排序。我也尝试使用startAt(futuredatestamp).endAt(pastdatestamp)
但没有工作。我想对此进行排序:
"NOT20170828140827" : {
"code" : "Your order status has been updated to Rejected",
"date" : "2017/08/28 14:08:27",
"title" : "Order update SPB20170825095233542"
},
"NOT20170828140436" : {
"code" : "Your order status has been updated to Delivered",
"date" : "2017/08/28 14:04:36",
"title" : "Order update SPB20170825095233542"
},
"NOT20170828132901" : {
"code" : "Your order status has been updated to Rejected",
"date" : "2017/08/28 13:29:01",
"title" : "Order update SPB20170825095233542"
},
"NOT20170828115852" : {
"code" : "Your order status has been updated to Rejected",
"date" : "2017/08/28 11:58:52",
"title" : "Order update SPB20170825095233542"
},
"NOT20170828014147" : {
"code" : "Your order status has been updated to IN TRANSIT",
"date" : "2017-08-28 01:41:47",
"title" : "Order update : SPB20170825095233542"
}
使用过滤器参数时有点困惑。
请帮帮我。提前谢谢
答案 0 :(得分:2)
假设您在Recyclerview中显示来自Firebase的数据,请添加此代码。
import matplotlib.pyplot as plt
plt.plot(df1.as_matrix(['Score']),df1.as_matrix(['Score']))
上面的代码做了什么,它反转了recyclerview的内容。
答案 1 :(得分:0)
在Firebase数据库中保存日期和时间的最佳做法是使用TIMESTAMP
将其保存为ServerValue.TIMESTAMP
,如下所示:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
Map map = new HashMap();
map.put("time", ServerValue.TIMESTAMP);
yourRef.child("yourNode").updateChildren(map);
请记住,您将TIMESTAMP保存为Map
,但您要将其检索为long
。为了获得数据,我建议你使用这种方法:
public static String getTimeDate(long timeStamp){
try{
DateFormat dateFormat = getDateTimeInstance();
Date netDate = (new Date(timeStamp));
return dateFormat.format(netDate);
} catch(Exception e) {
return "date";
}
}
然后,查询中的orderBy()
方法肯定会有效。