iOS 检查指定日期是否在当前日期之前

时间:2024-04-24 20:06:38

iOS检查指定日期是否在当前日期之前, 直接上代码:

- (BOOL)checkProductDate: (NSString *)tempDate {

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

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

    NSDate *date = [dateFormatter dateFromString:tempDate];

    // 判断是否大于当前时间
if ([date earlierDate:[NSDate date]] != date) { return true;
} else { return false;
} }