我正在尝试将事件添加到日历,但 event.startDate 输出为空。
event.startDate = [formatter dateFromString:dateandtime];
谁能告诉我为什么?
我检查了格式化程序,一切都很好..但我没有保存事件。
请找到代码供您参考。
-(IBAction)ADDEvent
{
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
[formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ +-HHMM"]; // SPOT the difference in this line
NSString *dateandtime =[NSString stringWithFormat:@"%@",self.eventtime];
EKEventStore *eventstore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore: eventstore];
event.title = self.eventname;
event.startDate = [formatter dateFromString:dateandtime];
event.endDate=[[formatter dateFromString:dateandtime] dateByAddingTimeInterval:(30*60)];
NSLog(@"%@",[[formatter dateFromString:dateandtime] dateByAddingTimeInterval:(30*60)]);
NSLog(@"%@",dateandtime);
[event setCalendar:[eventstore defaultCalendarForNewEvents]];
}}