IOS 判断当前时间是否出于某个时间段内
2022-05-17 本文已影响0人
本客
/**
- 判断当前时间是否处于某个时间段内
- @param startTime 开始时间
- @param endTime 结束时间
*/
- (BOOL)validateWithStartTime:(NSString *)startTime withExpireTime:(NSString *)endTime {
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
NSDate *start = [dateFormat dateFromString:startTime];
NSDate *end = [dateFormat dateFromString:endTime];
if ([today compare:start] == NSOrderedDescending && [today compare:end] == NSOrderedAscending) {
return YES;
}
return NO;
}