ios 计算时间差(可能是升级9以后上次的计算方法有问题了)

2016-07-22  本文已影响54人  孟维学

- (NSString*)intervalFromLastDate: (NSString*) dateString1toTheDate:(NSString*) dateString2

{

NSDateFormatter*date=[[NSDateFormatteralloc]init];

[datesetDateFormat:@"yyyy-MM-dd"];

NSDate*d1=[datedateFromString:dateString1];

NSTimeIntervallate1=[d1timeIntervalSince1970]*1;

NSDate*d2=[datedateFromString:dateString2];

NSTimeIntervallate2=[d2timeIntervalSince1970]*1;

NSTimeIntervalcha=late2-late1;

NSString*timeString=@"";

NSString*house=@"";

NSString*min=@"";

NSString*sen=@"";

sen = [NSStringstringWithFormat:@"%d", (int)cha%60];

//min = [min substringToIndex:min.length-7];

//秒

sen=[NSStringstringWithFormat:@"%@", sen];

min = [NSStringstringWithFormat:@"%d", (int)cha/60%60];

//min = [min substringToIndex:min.length-7];

//分

min=[NSStringstringWithFormat:@"%@", min];

//小时

house = [NSStringstringWithFormat:@"%d", (int)cha/3600/24];

//house = [house substringToIndex:house.length-7];

house=[NSStringstringWithFormat:@"%@", house];

timeString=[NSStringstringWithFormat:@"%@",house];

returntimeString;

}

上一篇下一篇

猜你喜欢

热点阅读