判断日期时间在一个区间范围内,时间为时间戳

// 判断是否在当前时间区间内
- (BOOL)isBetweenFromData:(NSString *)fromdataString toDate:(NSString *)todataString{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *fromDate = [NSDate dateWithTimeIntervalSince1970:[fromdataString floatValue]];
    NSDate *toDate = [NSDate dateWithTimeIntervalSince1970:[todataString floatValue]];
    
    NSDate *currentDate = [NSDate date];
    
    if ([currentDate compare:fromDate]==NSOrderedDescending && [currentDate compare:toDate]==NSOrderedAscending) {
        // 在规定日期之间
        return YES;
    }
    return NO;
}

你可能感兴趣的:(判断日期时间在一个区间范围内,时间为时间戳)