我試圖獲得計時器的總分鐘數。我已經有了秒鐘的工作。這是我如何得到「總秒數」:如何獲得「總分鐘數」(TIMER)
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [gregorian components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:time];
NSInteger hour = [comps hour];
NSInteger minute = [comps minute];
NSLog(@"Hour:%i", hour);
NSLog(@"minute:%i", minute);
NSInteger secs =hour * 60 * 60 + minute * 60;
NSNumber *elapsedSeconds = [[NSNumber alloc] initWithInt:secs];
NSDictionary *myDict = [NSDictionary dictionaryWithObject:elapsedSeconds forKey:@"TotalSeconds"];
除非使用GC,否則不要忘記釋放或自動釋放已分配的對象。 – 2011-04-24 21:50:41