/** * 判断当前时间是否处于某个时间段内 * * @param startTime 开始时间 * @param expireTime 结束时间 */ - (BOOL)validateWithStartTime:(NSString *)startTime withExpireTime:(NSString *)expireTime { NSDate *today = [NSDate date]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; // 时间格式,此处遇到过坑,建议时间HH大写,手机24小时进制和12小时禁止都可以完美格式化 [dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm"]; NSDate *start = [dateFormat dateFromString:startTime]; NSDate *expire = [dateFormat dateFromString:expireTime]; if ([today compare:start] == NSOrderedDescending && [today compare:expire] == NSOrderedAscending) { return YES; } return NO; }
如果你不是在wb145230博客园看到本文,请点击查看原文.