问题
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