want to understand the Difference between the Difference between dateFromString and stringFromDate for this pattern "YYYY".
Because I have written the below logics for dateFromString and stringFromDate but result is different like Mon Dec 30 09:05:00 2019 and 2020/12/30 09:05
// convert string to date
NSString *dateStr = @"2019-12-30 09:05";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm"];
//NSDate *date = [dateFormat dateFromString:dateStr];
NSDate *dateValue = [dateFormat dateFromString:dateStr];
NSLog(@"string to date == %@",dateValue);
// convert date to string
NSDateFormatter *df1 = [[NSDateFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[df1 setLocale:locale];
[df1 setDateFormat:@"YYYY/MM/dd HH:mm"];
NSString *datestr = [df1 stringFromDate:dateValue];
NSLog(@"date to string == %@", datestr);
so out put is below
string to date == Mon Dec 30 09:05:00 2019
date to string == 2020/12/30 09:05
Both or same pattern YYYY It is working as a week based calander. but why year value 2019 and 2020 is differing when using following methods dateFromString and stringFromDate?