According to the given timestamp to get the distance from the current time interval (just a few minutes ago, a few months…)

The content returned by this code is:

Time < 1min
1min; return “just” < time < 1H returns shows “XX minutes ago”;
1H < time < 24h “XX return today XX”;
24h < time < 48h “XX XX returned yesterday”;
48h < time < in January 1st this year to return “XX June XX XX XX
time”; > January 1st this year returns “XXXX year XX month XX day”.
“yyyy-MM-dd HH:mm”

* * according to timestamp returns from the current time long * * return beTime timestamp string from the current time (just a few minutes ago, today a few points yesterday, some sort of...) - * / (NSString *) distanceTimeWithBeforeTime: (double) beTime NSTimeInterval [[NSDate date]timeIntervalSince1970] {now = double; distanceTime = now - beTime NSDate *datenow; date] = [NSDate; NSString = *dateNowYearStr [[NSString stringWithFormat:@ datenow] substringWithRange:NSMakeRange, "% @" (0, 4)]; NSString * distanceStr; NSDate * beDate = [NSDate dateWithTimeIntervalSince1970:beTime]; NSDateFormatter * DF = [[NSDateFormatter alloc]init]; [df setDateFormat:@ "yyyy"]; NSString * yearStr = [df stringFromDate:beDate]; [df setDateFormat:@ "HH:mm"]; NSString * timeStr = [df stringFromDate:beDate]; [df setDateFormat:@ "DD"]; NSString * nowDay = [df stringFromDate:[NSDate date]]; NSString * lastDay = [df stringFromDate:beDate]; if (distanceTime < 60) {// less than a minute distanceStr = @ "just";} else if (distanceTime < 60*60) {// less than an hour distanceStr [NSString stringWithFormat:@ = "%ld minutes ago" (long), distanceTime/60] else (distanceTime < if;}; 24*60*60 & amp; & [nowDay integerValue] = [lastDay integerValue]) {// time less than one day distanceStr = [NSString stringWithFormat:@ today, timeStr]}% @ "; else if (distanceTime< 24*60*60*2 & & [nowDay integerValue]! = [lastDay integerValue]) {if ([nowDay integerValue] - [lastDay integerValue] ==1 || ([lastDay integerValue] - [nowDay integerValue] > 10 & & [nowDay integerValue] = = 1)) {distanceStr = [NSString stringWithFormat:@ timeStr];}% @ yesterday ", else{[df setDateFormat:@" MM-dd HH:mm "] = [df stringFromDate:beDate]; distanceStr else if;}} ([yearStr isEqualToString:dateNowYearStr]) {/ / this year [df setDateFormat:@" MM-dd HH:mm "]; distanceStr = [df stringFromDate: beDate] else{;} / / not the year [df setDateFormat:@" yyyy-MM-dd "] = [df stringFromDate:beDate]; distanceStr return distanceStr;}};