Firebase endAt()不能使用日期字符串? [英] Firebase endAt() not working with date string?

查看:129
本文介绍了Firebase endAt()不能使用日期字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  23-Oct-2016 07:00:11 AM 

现在我是发射这个查询,我得到所有的数据开始日期

 查询查询= mDatabase.orderByChild(时间)。 startAt(2016年10月23日)

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

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

 查询查询= mDatabase.orderByChild(time)。startAt(2016年10月23日)。endAt(PM); 


解决方案

做的事情是保证给你一个难的时间。字符串按字典顺序排列,而您通常希望将日期按时间顺序排列。这两个命令并不总是匹配。

存储查询的日期/时间的最佳方式是简单的 timestamp :自UNIX纪元以来的毫秒数。



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


Pretty basic question in here

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")

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

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.

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

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()不能使用日期字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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