I am using EventKit.framework to get events stored in EKEventStore
.
How can I get only today's events i.e from morning 00:00AM to 11:59PM (00:00 to 23:59). Timezone may be anything.
I am using below piece of code, but it is giving next day event also. It is adding 24 hours to today's date.
-(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]];
}
How to change NSPredicate
for above requirement?