我想在iPhone的默认日历中写活动,但我面临时差问题,我正在开始日期18-02-2014 08:00 PM和结束日期25-02-2014 11:30 PM我正在使用但它是写作开始日期18-02-2014 12:00 PM和结束日期25-02-2014 12:30 PM。我不知道我错在哪里。我怎么能在同一时间写它。< / p>
-(void)writeEventwithTitle:(NSString*)aTitle startDate:(NSDate*)strtDate endDate:(NSDate*)ndDate{
_eventStore = [[EKEventStore alloc] init];
[_eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError* error){
if (!granted) {
return ;
}
EKEvent *event = [EKEvent eventWithEventStore:_eventStore];
event.title = aTitle;
event.startDate = strtDate;
event.endDate = ndDate;
[event setCalendar:[_eventStore defaultCalendarForNewEvents]];
NSError* err;
[_eventStore saveEvent:event span:EKSpanFutureEvents commit:YES error:&err];
}];
}
-(void)startWritingEvent{
for (int i = 0 ; i < [_eventArray count]; i++) {
id dict= [_eventArray objectAtIndex:i];
NSString* eventTitle = [dict objectForKey:Title];
NSDictionary* eventBeginArray = [dict objectForKey:EventBegin];
NSDate* startDate = [self dateFromDate:[eventBeginArray objectForKey:StartDate] andTime:[eventBeginArray objectForKey:StartTime]];
NSDate* endDate = [self dateFromDate:[eventBeginArray objectForKey:EndDate] andTime:[eventBeginArray objectForKey:EndTime]];
[self writeEventwithTitle:eventTitle startDate:startDate endDate:endDate];
}
}
-(NSDate*)dateFromDate:(NSString*)date andTime:(NSString*)time{
NSString *eventDttm = [[NSString alloc] init];
eventDttm = [NSString stringWithFormat:@"%@ %@",date,time];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy HH:mm a"];
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
//conversion of NSString to NSDate
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:eventDttm];
return dateFromString;
}