首页 > 基础资料 博客日记

JavaSE-时间差

2023-08-05 16:42:02基础资料围观219

文章JavaSE-时间差分享给大家,欢迎收藏Java资料网,专注分享技术知识

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;

    }

文章来源:https://www.cnblogs.com/a999/p/16525310.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!

标签:

相关文章

本站推荐

标签云