优雅的时间格式化方式

/**
 * @param time
 * @return
 * 时间间隔
 */
public static String dayToNow(long time) {
    Calendar now = Calendar.getInstance();
    long minute = (now.getTimeInMillis() - time) / 60000;
    if (minute < 60) {
        if (minute == 0) {
            return "刚刚";
        } else {
            return minute + "分钟前";
        }
    }
    long hour = minute / 60;
    if (hour < 24) {
        return hour + "小时前";
    }
    long day = hour / 24;
    if (day < 30) {
        return day + "天前";
    }
    long month = day / 30;
    if (month < 11) {
        return month + "个月前";
    }
    long year = month / 12;
    return year + "年前";
}

你可能感兴趣的:(优雅的时间格式化方式)