EKEventStore 通过了 NSDate 并减去了几个月
我正在努力向 iPhone 日历添加一个活动,一切都按计划进行,但是,我的开始日期减去了一个半月多一点。当日期实际上是 2012 年 2 月 14 日时...添加到日历中的事件日期是 2011 年 12 月 25 日。expiresOn.text
是一个类似于“Feb 14, 2012”的字符串。任何人都可以提供有关可能导致问题的原因的见解吗?
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = [NSString stringWithFormat: @"%@ Expiration", self.navigationItem.title];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSString *dateString = [NSString stringWithFormat:@"0800 %@", expiresOn.text];
[dateFormat setDateFormat:@"hhmm MMM dd, YYYY"];
NSDate *date = [dateFormat dateFromString:dateString];
event.startDate = date;
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
EKEventViewController *viewController = [[EKEventViewController alloc] initWithNibName:nil bundle: nil];
viewController.event = event;
viewController.allowsEditing = YES;
I'm working to add an event to the iPhone calendar and everything goes as planned, however, a little over a month and a half is being subtracted from my startDate. When the date is actually Feb 14, 2012... the event date added to the calendar is Dec 25, 2011.
expiresOn.text is a string like "Feb 14, 2012". Can anyone offer insight as to what may be causing the problem?
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = [NSString stringWithFormat: @"%@ Expiration", self.navigationItem.title];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSString *dateString = [NSString stringWithFormat:@"0800 %@", expiresOn.text];
[dateFormat setDateFormat:@"hhmm MMM dd, YYYY"];
NSDate *date = [dateFormat dateFromString:dateString];
event.startDate = date;
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
EKEventViewController *viewController = [[EKEventViewController alloc] initWithNibName:nil bundle: nil];
viewController.event = event;
viewController.allowsEditing = YES;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只是在格式化程序的设置中存在区分大小写的拼写错误。
使用:
我希望这会有所帮助!
You simply have a case sensitive typo in the set up for your formatter.
Use:
And I hope this helps!