ios 两个时间差多少天时分
2019-07-23 本文已影响0人
丶王无情
计算两个时间差:
NSDateFormatter *date = [[NSDateFormatter alloc]init];
[datesetDateFormat:@"yyyy/MM/dd HH:mm:ss"];
NSDate*startD = [datedateFromString:time1];
NSDate*endD = [datedateFromString:time2];
NSTimeInterval start = [startD timeIntervalSince1970]*1;
NSTimeInterval end = [endD timeIntervalSince1970]*1;
NSTimeIntervalvalue = end - start;
NSString*days = [NSStringstringWithFormat:@"%d",(int)value / (24*3600)];
NSString*hours = [NSStringstringWithFormat:@"%d",(int)(value-days.integerValue*24*3600) / 3600];
NSString*minutes = [NSStringstringWithFormat:@"%d",(int)value /60%60];
NSString*format_time = [NSStringstringWithFormat:@"距离截止:%@天%@时%@分",days,hours,minutes];