Firebase endAt() 不适用于日期字符串?

编程入门 行业动态 更新时间:2024-10-18 16:51:17
本文介绍了Firebase endAt() 不适用于日期字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这里有一个非常基本的问题

Pretty basic question in here

我在 Firebase DB 中存储的日期字符串是这样的

My Stored Date String is like this in Firebase DB

23-Oct-2016 07:00:11 AM

现在我正在触发这个查询,我正在获取从那个日期开始的所有数据

Now i am firing this query , i am getting all the data starting with that date

Query query = mDatabase.orderByChild("time").startAt("23-Oct-2016")

现在我还想按当前 AM/PM 时间过滤我正在尝试这样的查询,但它对结果没有影响.

Now I also want to filter by current AM/PM time i am trying query like this but it has no effect on results.

如果当前时间是 PM ,基本上它不应该返回任何对象,我不知道为什么它不起作用.

Basically it should not return any object if the current time is PM , i don't know why its not working .

Query query = mDatabase.orderByChild("time").startAt("23-Oct-2016").endAt("PM");

推荐答案

像您所做的那样将日期和时间存储为可读字符串肯定会给您带来困难.字符串按字典顺序排列,而您通常希望按时间顺序处理日期.这两个订单并不总是匹配.

Storing dates and times as readable strings like you seem to be doing is guaranteed to give you a hard time. Strings are lexicographically ordered, while you typically want to treat dates as chronologically ordered. The two orders don't always match up.

存储用于查询的日期/时间的最佳方式是作为一个简单的时间戳:毫秒数自 UNIX 时代以来.

The best way to store a date/time for querying is as a simple timestamp: the number of milliseconds since the UNIX epoch.

如果您坚持将日期和时间存储为更易读的字符串,最好将它们存储为既可读又按字典顺序和时间顺序排序的格式,例如 ISO 8601 格式:20161023T150422.这是我输入的当前时间:UTC 时间 2016 年 10 月 23 日下午 3:04.

If you insist on storing the dates and times as more readable string, your better of storing them in a format that is both readable and will sort the same in both lexicographical and chronological order, such as the ISO 8601 formats: 20161023T150422. This is the current time as I type this: October 23, 2016 3:04 PM UTC.

更多推荐

Firebase endAt() 不适用于日期字符串?

本文发布于:2023-11-30 17:37:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650918.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   不适用于   日期   Firebase   endAt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!