我有這樣的日期格式:NSD每小時24小時制?
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"HH:mm"];
如果我用這個:
NSDate *myDate = [timeFormatter dateFromString:@"13:00"];
它返回:
"1:00"
這是因爲模擬器已關閉24小時。但是,對於我的應用我真正需要的,而不是"13:00"
"1:00"
--- 編輯1 ---
增加了新的代碼:
NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"HH:mm"];
NSDate *timeForFirstRow = [timeFormatter dateFromString:@"13:00"];
NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:timeForFirstRow];
NSInteger hour = [dateComponents hour]; //This will be 1 instead of 13
NSInteger minute = [dateComponents minute];
你能告訴你在哪裏顯示「返回」的代碼? – falconcreek 2011-03-12 17:10:58