IOS 判断当前时间是否出于某个时间段内

/**

  • 判断当前时间是否处于某个时间段内
  • @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;
}

你可能感兴趣的:(IOS 判断当前时间是否出于某个时间段内)