First, your date format is wrong — the second line should be [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.000Z"];
— that is, you need the ss.
after the mm:
but before the 000Z
. This will give you the correct NSDate.
Next, you need to create a new date formatter with the format @"dd.M.yyyy"
(or @"d.M.yyyy"
if you want to remove the leading zero if the day is a single digit as well) and call stringFromDate:
on that for the NSLog.
Just to recap, the whole chunk of code would be
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.000Z"];
NSDate *theDate = [dateFormatter dateFromString:stringDate];
NSDateFormatter *printFormatter = [[NSDateFormatter alloc] init];
[printFormatter setDateFormat:@"dd.M.yyyy"];
NSLog(@"%@",[printFormatter stringFromDate:theDate]);
4
solved Using NSDateFormatter in objective-C [duplicate]