编程语言
首页 > 编程语言> > JavaSE-时间差

JavaSE-时间差

作者:互联网

public static String getDiffDateStr(Date startTime,Date endTime){
        long diff = endTime.getTime() - startTime.getTime();

        long diffSeconds = diff / 1000 % 60;

        long diffMinutes = diff / (60 * 1000) % 60;

        long diffHours = diff / (60 * 60 * 1000) % 24;

        long diffDays = diff / (24 * 60 * 60 * 1000);

        String diffTimeStr = "";
        if (0 != diffDays) {
            diffTimeStr = diffTimeStr + diffDays + "天";
        }
        if (0 != diffHours) {
            diffTimeStr = diffTimeStr + diffHours + "小时";
        }
        if (0 != diffMinutes) {
            diffTimeStr = diffTimeStr + diffMinutes + "分钟";
        }
        if (0 != diffSeconds) {
            diffTimeStr = diffTimeStr + diffSeconds + "秒";
        }

        return diffTimeStr;

    }

标签:diffSeconds,long,时间差,60,diffTimeStr,diff,JavaSE,1000
来源: https://www.cnblogs.com/a999/p/16525310.html