starttime = 23:00 pm 结束时间=早上5点
我需要开始时间到结束时间的总和时间 我正在尝试这段代码但对我没有帮助
NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateFormat:@"HH"];
NSDate *currentTime = [NSDate date];
NSDate *openTime = [formatter dateFromString:start];
NSDate *closeTime = [formatter dateFromString:end ];
NSCalendar *calender = [NSCalendar currentCalendar];
NSDateComponents *currentTimeComponents = [calender components:NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:currentTime];
NSDateComponents *openTimeComponents = [calender components:NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:openTime];
NSDateComponents *closeTimeComponents = [calender components:NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:closeTime];
NSUInteger currentTimeSeconds = currentTimeComponents.hour;
NSUInteger openTimeSeconds = openTimeComponents.hour;
NSUInteger closeTimeSeconds = closeTimeComponents.hour;
if (currentTimeSeconds>openTimeSeconds && currentTimeSeconds<closeTimeSeconds) {
NSLog(@"Time Between Open and Close Time %lu",(unsigned long)currentTimeSeconds);
}
它显示0个开胃菜。 请帮帮我一个? 提前谢谢