我試圖從一個月和一年中生成一個NSDate(全部爲整數格式)。從日,月和年生成NSDate
現在我的嘗試是這樣的:
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
NSNumber *day = [dataSource valueForKey:@"day"];
NSNumber *month = [dataSource valueForKey:@"month"];
NSNumber *year = [dataSource valueForKey:@"year"];
[components setDay:[day intValue]];
[components setMonth:[month intValue]];
[components setMonth:[year intValue]];
NSDate *_date = [calendar dateFromComponents:components];
然而,_DATE輸出以下時天= 24個月= 8年= 2011:
0168-07-25 4時56分02秒+0000
我必須做一些可怕的錯誤,但我不知道是什麼。任何人都知道可能會發生什麼?
來到這裏,在2016年底,這問題仍然是有幫助的。鑑於有30個有用的投票,我會投票重新打開,如果可能的話。此外,沒有任何一位精選的選民在他們的頂級標籤中查看他們的個人資料時,有objective-c,iOS,cocoa-touch,cocoa,nsdate。 – matrixugly