timeDiff = [dateE timeIntervalSinceDate:dateS ];
通过上面这句话就能计算时间差
if ((60*60*24*2)>=difftime&&difftime>=(60*60*24)) {
return startTime;
} else if((60*60)<=difftime && difftime <=(60*60*24))
{
int hour=(difftime)/3600;
int min=(difftime -hour*60*60)/60;
if (min==0) {
return [NSString stringWithFormat:@"%d hour ago",hour];
}else{
return [NSString stringWithFormat:@"%d hour %d min ago",hour,min];
}
}else if(60<=difftime&&difftime<(60*60))
{
int min=difftime/60;
return [NSString stringWithFormat:@"%d min ago",min];
}else if(0<=difftime&&difftime<(60))
{
return [NSString stringWithFormat:@"new"];
}
return @"error";
}
显示过去时间
https://github.com/CZXBigBrother/MCTimeDifference
github下载地址