[英]Query parse.com by time, not date
Is there a way to query from parse.com CreatedAt column by the time only? 有没有一种方法可以仅按时间从parse.com CreatedAt列进行查询? My goal is to query all the records that were CreatedAt between say 6 and 12 o'clock regardless of the date (though I will need to attach some date range also). 我的目标是查询所有说在6点到12点之间的CreatedAt记录,而不管日期如何(尽管我也需要附加一些日期范围)。 I am using parse's .NET API. 我正在使用解析的.NET API。 In my mind I thought something like this might work, but sadly all I got was InvalidOperationException : 在我的脑海中,我以为这样的事情可能会奏效,但可悲的是,我得到的只是InvalidOperationException :
pQuery = from hit in pQuery
where ((DateTime)hit.CreatedAt).Hour >= 6
&& ((DateTime)hit.CreatedAt).Hour <= 12
select hit;
Of course I always could filter results after the query using business logic, but that would hinder the performance. 当然,我总是可以在查询后使用业务逻辑过滤结果,但这会影响性能。 Would love a query solution. 会喜欢一个查询解决方案。
I don't think you can do it the way you're thinking - the createdAt
field is just a UNIX timestamp. 我认为您无法按照自己的想法进行操作createdAt
字段只是UNIX时间戳。 Instead, you could try adding a new field (or fields) to track the time. 相反,您可以尝试添加一个或多个新字段来跟踪时间。 Create a beforeSave
method for that class that populates those fields anytime a new object gets created. 为该类创建一个beforeSave
方法,该方法将在创建新对象时填充这些字段。 Then you can query against those new fields. 然后,您可以查询这些新字段。
The tricky part here will be dealing with timezones, so take that into consideration. 这里棘手的部分将涉及时区,因此请考虑到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.