解析检查对象是否是今天创建的?目标-C [英] Parse check if object was created today? Objective-C

查看:33
本文介绍了解析检查对象是否是今天创建的?目标-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用程序编写一个 PFQuery,它只返回今天创建的对象.随着 NSDate 发生的所有贬值以及 NSDateFormatter 的重要性日益增加,我发现很难做到这一点.

I am trying to write a PFQuery for my application that returns only objects that were created today. With all the depreciations that happened to NSDate and the growing importance of NSDateFormatter I am finding rather hard to go about this.

我已经在伪代码中找到了这样的逻辑:

I have figured the logic to be like this in pseudo-code:

Query q = new Query();
q.whereDateGreaterThan(midnightThisMorning);
q.whereDateLessThan(midnightTonight);

我似乎无法弄清楚如何将 NSDate 对象设置为 12:00 AM(即 midnightThisMorning)并将另一个设置为 11:59今晚下午(将是 midnightTonight).

I can't seem to figure out how to get a NSDate object set to 12:00 AM (which would be midnightThisMorning) and another set to 11:59 PM tonight (which would be midnightTonight).

推荐答案

查看 NSCalendarstartOfDayForDate 方法来查找当天的开始.

Check out NSCalendar's startOfDayForDate method to find the start of the current day.

要查找当天的结束时间,您需要在从 startOfDayForDate 返回的日期中添加一天,然后减去一秒.

To find the end of the current day, you'll want to add a day to the date returned from startOfDayForDate and then subtract one second.

这篇关于解析检查对象是否是今天创建的?目标-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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