我的格式爲HH:mm:ss(24小時)的開始時間和結束時間。在IOS中兩次之間比較時間(格式爲HH:MM:SS)
我需要比較當前時間是否在開始和結束時間之間。
我編寫邏輯的方式是,如果開始時間晚於結束時間,它會將24小時添加到開始時間。
if (shift.sShiftStart < shift.sShiftEnd) {
startTime = shift.sShiftStart;
startTimeInt = [[shift.sShiftStart substringToIndex:2] integerValue];
startTimeInt2 = startTimeInt + 24;
finalStartTime = [startTime stringByReplacingCharactersInRange:NSMakeRange(0, 2) withString:[NSString stringWithFormat:@"%d", startTimeInt2]];
} else {
finalStartTime = shift.sShiftStart;
}
現在我想檢查我的currentTime的是finalStartTime和結束時間(均爲在HH:mm:ss的格式)之間
這有很好的答案http://stackoverflow.com/questions/8183472/how-to-compare-two-nsdate-objects-in-objective-c – Vinodh