NSDateFormatter incorrect date conversion

advertisements

I am using NSDateFormatter, to convert NSString to NSDate.

For e.g if my NSString value is Jun 24,2015 Then it is getting converted as 2015-06-23 18:30:00 +0000, which is incorrect.

It should be "24" instead of "23".

I am using below code to convert.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM dd,yyyy"];
NSLog(@"%@",[formatter dateFromString:strDate]);

Please help me to figure out the issue.

Thanks


this might help you out. Add the following code.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];