I am formatting a NSDate in my application. Using below code:
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"YYYY-MM-dd HH:mm:ss";
NSString* currentDateTime = [dateFormatter stringFromDate:now];
NSLog(@"CurrentDateTime:%@", currentDateTime);
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
currentDateTime = [dateFormatter stringFromDate:now];
NSLog(@"CurrentDateTime 1 :%@", currentDateTime);
[dateFormatter release];
But this work fine for whole year but fails after 27-Dec. It adds a year after format the date of 27-Dec or above. Only when we use the "YYYY"
instead of "yyyy"
. Its again works fine after the year change. So please can you suggest the reason behind this.