1. 程式人生 > >ios NSTimeInterval獲取時間間隔

ios NSTimeInterval獲取時間間隔

NSDateFormatter *formatter = [[NSDateFormatteralloc] init];

[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSDate *date1 = [formatter dateFromString:startTime];

NSDate *date2 = [NSDatedate];

NSTimeInterval aTimer = [date2timeIntervalSinceDate:date1];

int hour = (int)(aTimer/3600);

int minute = (int

)(aTimer - hour*3600)/60;

int second = aTimer - hour*3600 - minute*60;

NSString *dural = [NSStringstringWithFormat:@"%d%d%d", hour, minute,second];