-1
我試圖[NSDate的日期],但功能dateFromComponents返回錯誤值的月和年設置,這是我的代碼:dateFromComponents返回錯誤值
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian]; // Setup an NSCalendar
NSDateComponents *components = [gregorianCalendar components: NSUIntegerMax fromDate: [NSDate date]]; // Setup NSDateComponents
[components setTimeZone:[NSTimeZone defaultTimeZone]];
[components setMonth:monthInt];
[components setYear:yearInt];
// Setup the new date
NSDate *dateToCompare = [gregorianCalendar dateFromComponents: components];
yearInt是2014年和monthInt是12 ,但它報告12-2015而不是2014年,這是爲什麼?
謝謝!