+(NSString *)getTimeDifferenceWithString:(NSString *)string
{
NSDate * data = [NSDate date];
NSDateFormatter *dateFomatter = [[NSDateFormatter alloc] init];
dateFomatter.dateFormat = @"yyyy-MM-dd HH:mm";
//當(dāng)前時(shí)間
NSString * nowDateString = [dateFomatter stringFromDate:data];
data = [dateFomatter dateFromString:nowDateString];
NSTimeInterval timeNo;
NSDate * date;
NSString * time;
NSDate * expirDate;
timeNo = [string doubleValue];
date = [NSDate dateWithTimeIntervalSince1970:timeNo];
time = [dateFomatter stringFromDate:date];
//截止時(shí)間
expirDate = [dateFomatter dateFromString:time];
NSCalendar * calendar = [NSCalendar currentCalendar];
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth| NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute;
NSDateComponents *dateCom = [calendar components:unit fromDate:data toDate:expirDate options:0];
if (dateCom.year<0)
{
return [NSString stringWithFormat:@"%ld年前",(long)-dateCom.year];
}
else if (dateCom.month<0)
{
return [NSString stringWithFormat:@"%ld月前",(long)-dateCom.month];
}
else if (dateCom.day<0)
{
return [NSString stringWithFormat:@"%ld天前",(long)-dateCom.day];
}
else if (dateCom.hour<0)
{
return [NSString stringWithFormat:@"%ld小時(shí)前",(long)-dateCom.hour];
}
else if (dateCom.minute<0)
{
return [NSString stringWithFormat:@"%ld分鐘前",(long)-dateCom.minute];
}
return @"剛剛";
}