当前时间大于等于预定时间,即请求下面接口,反之请求另外接口,代码贴在下面,粘贴上自己代码就可以使用:
- (void)viewDidLoad {
[super viewDidLoad];
NSDate*currentDate = [NSDatedate];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormattersetDateFormat:@"YYYY-MM-dd"];
NSString* currentDateStr = [dateFormatterstringFromDate:currentDate];
intcomparisonResult = [selfcompareDate:currentDateStrwithDate:@"自己定义个时间"];
if(comparisonResult >0){
//endDate 大
[self jsusWebView];
}else{
[self requestMainURL];
}
// Do any additional setup after loading the view from its nib.
}
//比较两个日期大小
-(int)compareDate:(NSString*)startDate withDate:(NSString*)endDate{
intcomparisonResult;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formattersetDateFormat:@"yyyy-MM-dd"];
NSDate *date1 = [[NSDate alloc] init];
NSDate *date2 = [[NSDate alloc] init];
date1 = [formatterdateFromString:startDate];
date2 = [formatterdateFromString:endDate];
NSComparisonResultresult = [date1compare:date2];
NSLog(@"result==%ld",(long)result);
switch(result)
{
//date02比date01大
case NSOrderedAscending:
comparisonResult =1;
break;
//date02比date01小
case NSOrderedDescending:
comparisonResult = -1;
break;
//date02=date01
case NSOrderedSame:
comparisonResult =0;
break;
default:
NSLog(@"erorr dates %@, %@", date1, date2);
break;
}
returncomparisonResult;
}