Question

NSString *dateString2 = record.trigger_end_date;
NSLog(@"dateString2  is%@%@",record.trigger_end_date,dateString2);
NSDateFormatter *formatter2 = [[NSDateFormatter alloc]init];
formatter2.dateFormat = @"yyyy-MM-dd";
NSDate *date2 = [formatter2 dateFromString:dateString2];
NSLog(@"date2 is%@",date2);

Here I'm getting log for NSLog(@"dateString2 is%@%@",record.trigger_end_date,dateString2); as dateString2 is2014-04-30T00:00:002014-04-30T00:00:00 but NSLog(@"date2 is%@",date2); is date2 is(null)

Was it helpful?

Solution 2

I would close this topic as a duplicate, but I can't decide which other topic to choose (there are so many questions asking for the same), so here is an answer:

formatter2.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";

OTHER TIPS

i know this question false in duplicate category & i flagged it as well. but i am answering here with explanation, if in case OP does not get the references .

 NSString *dateString = @"2014-04-30T00:00:00"; //input string
 NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
 [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];// fomatter in your case
 NSDate *date = [formatter dateFromString:dateString];
 NSLog(@"date is%@",date);

 output - date is2014-04-29 18:30:00 +0000
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top