我的时间间隔有问题。我需要以这种格式获得两次的间隔:HH:MM。如果我输入:15:35 和 16:35 没关系,但是当我输入 20:30 到 01:30 时,它给了我 18 小时的间隔.. 有人知道吗?
NSString *startDate= starthere.text;
NSString *endDate = endhere.text;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
NSDate *dateSelected = [dateFormatter dateFromString:startDate];
NSDate *dateSelected2 = [dateFormatter dateFromString:endDate];
[dateFormatter release];
if ([dateSelected2 earlierDate:dateSelected] == dateSelected2)
{
dateSelected2 = [dateSelected2 dateByAddingTimeInterval:86400];
}
interval = [dateSelected2 timeIntervalSinceDate:dateSelected];