-9
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)

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
Aruna M
  • 386
  • 3
  • 12

2 Answers2

0

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
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
-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";

tilo
  • 14,009
  • 6
  • 68
  • 85