我正在使用EventKit.framework来获取存储在EKEventStore
.
我怎样才能只获得今天的事件,即从早上00:00到晚上 11:59(00:00 到 23:59)。时区可能是任何东西。
我正在使用下面的代码,但它也在提供第二天的事件。它比今天的日期增加了 24 小时。
-(void) fetchEvents{
NSDate *startDate = [NSDate date] ;
//Create the end date components
NSDateComponents *tomorrowDateComponents = [[NSDateComponents alloc] init];
tomorrowDateComponents.day = 1;
NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:tomorrowDateComponents
toDate:startDate
options:0];
// We will only search the default calendar for our events
NSArray *calendarArray = [NSArray arrayWithObject:self.defaultCalendar];
// Create the predicate
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate
endDate:endDate
calendars:calendarArray];
// Fetch all events that match the predicate
NSMutableArray *events = [NSMutableArray arrayWithArray:[self.eventStore eventsMatchingPredicate:predicate]];
}
如何更改NSPredicate
以上要求?