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;
}

 

posted @ 2022-12-13 15:13  OIMMZC  阅读(337)  评论(0编辑  收藏  举报