The time interval for calculating two dates in iOS development, and the time interval for calculating two dates in ios development
// Create a formatted object
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[DateFormatter setDateFormat: @ "yyyy-MM-dd HH: mm: ss"];
// Create a date object
NSDate * date1 = [dateFormatter dateFromString: @ "2020-10-31 00:00:00"];
NSDate * date = [NSDate date];
// Calculation interval (in seconds)
NSTimeInterval time = [date1 timeIntervalSinceDate: date];
// Calculates the number of days, hours, minutes, and seconds.
Int days = (int) time)/(3600*24 );
Int hours = (int) time) % (3600*24)/3600;
Int minutes = (int) time) % (3600*24) % 3600/60;
Int seconds = (int) time) % (3600*24) % 3600% 60;
NSString * dateContent = [[NSString alloc] initWithFormat: @ "Only % I days % I hours % I minutes % I seconds", days, hours, minutes, seconds];
(% I can automatically convert the input to decimal, while % d won't convert)
// Value assignment display
UILabel * timeLab = (UILabel *) [self. view viewWithTag: 666666];
TimeLab. text = dateContent;