Objective-C NSDateFormatter 返回任意日期

Objective-C NSDateFormatter returning arbitrary date

NSString *string = [NSString stringWithFormat:@"%@-%ld %@",self.date,(long)  [self getYear],self.time];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];  
[dateFormat setDateFormat:@"EEE, MMM-dd-YYYY hh:mm"];
NSDate *date = [dateFormat dateFromString:string];
NSLog(@"date: %@",date);

如果我输入2016 年 2 月 29 日星期一9:00

我得到一个 输出 off 2015-12-21 03:30:00 +0000

与实际日期相差甚远

一个常见的错误/误解:

YYYY

Year (in "Week of Year" based calendars). Normally the length specifies the padding, but for two letters it also specifies the maximum length. This year designation is used in ISO year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems where week date processing is desired. May not always be the same value as calendar year.

标准日历年的正确说明符是小写 yyyy