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

2022-05-17  本文已影响0人  本客

/**

- (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;
}
上一篇下一篇

猜你喜欢

热点阅读