IOS判断当前日期在两个日期之间。

-(NSDate *)dateFromString:(NSString *)datestring


{

    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit;

    NSDateFormatter *format=[[NSDateFormatter alloc] init];

    [format setDateFormat:@"yyyy-MM-dd"];

    NSDate *fromdate=[format dateFromString:datestring];

    return fromdate;

    

}

- (BOOL)date:(NSDate*)date isBetweenDate:(NSDate*)beginDate andDate:(NSDate*)endDate

{

    if ([date compare:beginDate] == NSOrderedAscending)

        return NO;

    

    if ([date compare:endDate] == NSOrderedDescending)

        return NO;

    

    return YES;

}

你可能感兴趣的:(IOS)