我的应用程序是一个通用应用程序,在我的应用程序的一部分中,我必须在日历中添加事件我的代码在 iOS 4.x 和 5.x 中运行良好,但在 i 6.0 中,当我使用日期格式化程序将字符串转换为日期时,它返回下面的 iOS 6.0 中的 null 是代码:-
-(IBAction) addToPlanBttnClick:(id) sender
{
addToPlanBttn.tag =1;
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
EKEvent *newEvent = [EKEvent eventWithEventStore:eventStore];
// set event title start date and end date
NSString *str = conference.SeminarDate;
str = [[str stringByAppendingString:@" "] stringByAppendingString:conference.StartTime];
NSLog(@"%@",str);
newEvent.title = conference.Subject;
//NSString *pointDate = [[[NSString alloc] initWithString:dateLbl.text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// You can use current date or any other
//NSString *str1 = [[NSString alloc] initWithString:[[pointDate stringByAppendingString:@", 2012 "]stringByAppendingString:[str substringWithRange:NSMakeRange(0, 5)]]];
//NSLog(@"stri date----%@", str1);
NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"EEEE dd MMMM yyyy HH:mm"];
NSDate* startDate = [df dateFromString:str];
//[NSDate date];
NSLog(@"stri date----%@", startDate);
newEvent.startDate = startDate;
[newEvent setNotes:conference.BriefDescription];
NSString *str1 = conference.SeminarDate;
str1 = [[str1 stringByAppendingString:@" "] stringByAppendingString:conference.EndTime];
NSLog(@"%@",str1);
NSDate *endDate = [df dateFromString:str1];
NSLog(@"stri date----%@", endDate);
newEvent.endDate = endDate;
addController.eventStore = self.eventStore;
addController.event = newEvent;
addController.editViewDelegate = self;
[self presentViewController:addController animated:YES completion:nil];
}
我的日期字符串是 2013 年 2 月 12 日星期二 10:00,日期格式化程序[df setDateFormat:@"EEEE dd MMMM yyyy HH:mm"];
如代码所示,字符串生成的日期为:-2013-02-12 04:30:00 +0000 在模拟器和 iPad 中
但它在 iOS 6.0 上为空请建议我哪里错了。