Parse check if object was created today? Objective-C

跟風遠走 提交于 2019-12-11 19:39:26

问题


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

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


回答1:


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

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.



来源:https://stackoverflow.com/questions/34032116/parse-check-if-object-was-created-today-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!