1. 程式人生 > >日期年月日的比較以及判斷

日期年月日的比較以及判斷

日期 omd 再次 ont str col minute init lec

//對比的時間

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

[gregorian setFirstWeekday:2];

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

[dateFormatter setDateFormat:@"yyyyMMddHHmmss"];

NSDate *fromDate;

NSDate *toDate;

[gregorian rangeOfUnit:NSCalendarUnitMinute startDate:&fromDate interval:NULL forDate:[dateFormatter dateFromString:tisuTime]];

[gregorian rangeOfUnit:NSCalendarUnitMinute startDate:&toDate interval:NULL forDate:[NSDate date]];

NSDateComponents *dayComponents = [gregorian components:NSCalendarUnitMinute fromDate:fromDate toDate:toDate options:0];

if (dayComponents.minute >= 0 && dayComponents.minute<60) {

[self.tisuBtn setTitle: @"已加速" forState:UIControlStateNormal];

_tisuBtn.backgroundColor = BUTTON_UNSELECT;

}else{

//如果大於一小時之後就可以再次點擊

[self.tisuBtn setTitle: @"加速審核" forState:UIControlStateNormal];

_tisuBtn.backgroundColor = MAINCOLOR;

}

日期年月日的比較以及判斷