如何在Android

时间:2018-06-09 09:14:16

标签: android firebase firebase-realtime-database

enter image description here

这是我的Firebase数据结构的一部分。 我想按日期排序每条新闻。 所以我在互联网上搜索,我发现组织良好的文件。(https://www.firebase.com/docs/android/guide/retrieving-data.html#section-reading-once

但我不知道如何引用每篇新闻网站的子节点文章。

ref = database.getReference("news");
ref.(?).orderByChild("Pubdate").addListenerForSingleValueEvent(valueEventListener);

我想知道如何转换" Pubdate"字符串到firebase在排序时可以识别的内容。

1 个答案:

答案 0 :(得分:2)

不使用您正在使用的格式存储日期,而是使用自Unix纪元(1970年1月1日00:00:00 UTC)以来的毫秒数。

您可以致电System.currentTimeMillis()

如果您不想用当前格式替换数据项,可以添加包含Epoch时间的其他数据项,如下所示:

- -LBvaSIKGR....
    - author: "...."
    .....
    - pubdate: "Mon, 07 ...."
    - pubdateMillis: 1528536888
相关问题