ios – NSString to NSDate and again once more to NSString

I’ve a date string on this format: 2022-09-07T11:11:16+0300 and I need to convert it to NSDate and again once more to NSString, I take advantage of this code:

NSString * dateCreatedString = @"2022-09-07T11:11:16+0300";
self.dateFormat = [[NSDateFormatter alloc] init];
[self.dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate * date = [self.dateFormat dateFromString:dateCreatedString];


NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
formatter2.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSSZ";
NSString * newStr = [formatter2 stringFromDate:date];

And that i get this string date: 2022-09-07 04:11:16.000-0400 as a substitute of: 2022-09-07 11:11:16.000+0300.

Any thought what may be the issue?

Leave a Reply