问题描述:

I've make a calendar application to show events in calendar for iPad, so I have taken one demo calendar project. In this project, date pass by date picker in event is working properly, but I try to static string value to convert in nsdate and then pass this value is crash datePicker value and after string convert value both are same

DatePicker Value is =2014-06-18 14:35:31 +0000

after string convert value is = 2014-06-29 12:00:00 +0000

Here is my code:

[email protected]"ddddd";

NSString *dateStr = @"2014-06-29";

// Convert string to date object

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

[dateFormat setDateFormat:@"yyyy-MM-dd"];

NSDate *date2 = [dateFormat dateFromString:dateStr];

// Convert date object to desired output format

[dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss +SSSS"];

dateStr = [dateFormat stringFromDate:date2];

NSDate *dateFromStringf = [[NSDate alloc] init];

date =[dateFormat stringFromDate:date2];

NSLog(@"---C%@",date);

if (!foundDate){

ahnEvent *newEvent = [[ahnEvent alloc]init];

NSLog(@"%@",newEvent.date);

newEvent.date = date;

newEvent.events = [[NSArray alloc]initWithObjects:name, nil];

[events addObject:newEvent];

NSLog(@"%@",events);

}

[self.calendar setEvents:events];

};

this is my error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString dateComponent]: unrecognized selector sent to instance 0x8b0e0d0'

*** First throw call stack

:

I am using ahnCalendar Demo

Do you know where I did the mistake?

This is the link for Demo Project i have implement

ClickHere-ahnCalendar

网友答案:
// Convert date object to desired output format
        [dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss z"];
        dateStr = [dateFormat stringFromDate:date2];

Please try to use this instead of your date format

相关阅读:
Top