package com.zaiyun.common.utils;
import java.text.SimpleDateFormat;
import java.util.*;
public class FriendlyTimeUtils {
public static String friendly(Date date) {
Date now = new Date();
long ys = DateUtils.truncate(now, Calendar.YEAR).getTime();
long ds = DateUtils.truncate(now, Calendar.DAY_OF_MONTH).getTime();
long yd = DateUtils.truncate(date, Calendar.DAY_OF_MONTH).getTime();
long n = now.getTime();
long d = date.getTime();
if (d < ys) {
return new SimpleDateFormat("yyyy-MM-dd HH 点").format(date);
}
if ((ds - yd) == (24 * 60 * 60 * 1000)) {
return new SimpleDateFormat("昨天 HH 点").format(date);
}
if (d < ds) {
return new SimpleDateFormat("yyyy-MM-dd HH 点").format(date);
}
if (n - d > 60 * 60 * 1000) {
return new SimpleDateFormat("今天 HH 点").format(date);
}
if (n - d > 60 * 1000) {
return (long) Math.floor((n - d) * 1d / 60000) + "分钟前";
}
if (n - d > 1 * 1000) {
return "刚刚";
}
return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date);
}
}