Compare the number of different days between two dates, such as the number of months and the number of days
// Compare the selected Start Time and End Time
+ (BOOL) ComparisonString :( NSString *) str1 andString :( NSString *) str2
{
// NSString * dateStr = @ "01:01:01"; // input time
// 1. Obtain the time
NSDate * senddate = [NSDate date];
NSDateFormatter * dateformatter = [[NSDateFormatter alloc] init];
[Dateformatter setDateFormat: @ "yyyy-MM-dd"];
NSString * locationString = [dateformatter stringFromDate: senddate];
Str2 = locationString;
NSArray * arrya1 = [str1 componentsSeparatedByString: @ ""];
Str1 = arrya1.firstObject;
Arrya1 = [str2 componentsSeparatedByString: @ ""];
Str2 = arrya1.firstObject;
NSString * dateStr = [NSString stringWithFormat: @ "%@ 00:00:01", str1];
// Input time
// Convert the input time to the required format
NSDateFormatter * format = [[NSDateFormatter alloc] init];
[Format setDateFormat: @ "yyyy-MM-dd HH: mm: ss"];
NSDate * fromdate = [format dateFromString: dateStr];
NSTimeZone * fromzone = [NSTimeZone systemTimeZone];
NSInteger frominterval = [fromzone secondsFromGMTForDate: fromdate];
NSDate * fromDate = [fromdate dateByAddingTimeInterval: frominterval];
NSLog (@ "call time = % @", fromDate );
// NSString * dateStr1 = @ "20:28:40"; // input time
NSString * dateStr1 = [NSString stringWithFormat: @ "%@ 23:59:59", str2];
// Input time
// Convert the input time to the required format
NSDateFormatter * format1 = [[NSDateFormatter alloc] init];
[Format1 setDateFormat: @ "yyyy-MM-dd HH: mm: ss"];
NSDate * fromdate1 = [format1 dateFromString: dateStr1];
NSTimeZone * fromzone1 = [NSTimeZone systemTimeZone];
NSInteger frominterval1 = [fromzone1 secondsFromGMTForDate: fromdate1];
NSDate * fromDate1 = [fromdate1 dateByAddingTimeInterval: frominterval1];
NSLog (@ "call time 1 = % @", fromDate1 );
Double intervalTime = [fromDate1 timeIntervalSinceReferenceDate]-[fromDate timeIntervalSinceReferenceDate];
Long lTime = (long) intervalTime;
NSInteger iDays = lTime/60/60/24;
// NSInteger iMonth = lTime/60/60/24/12;
// NSInteger iYears = lTime/60/60/24/384;
// NSInteger iSeconds = lTime % 60;
// NSInteger iMinutes = (lTime/60) % 60;
// NSLog (@ "dat = % d", iDays );
If (iDays <= 0 ){
Return NO;
} Else {
Return YES;
}
}