0
点赞
收藏
分享

微信扫一扫

JAVA Date 时间与时间相差计算

棒锤_45f2 2023-11-08 阅读 49


JAVA Date 时间与时间相差计算


Date date = new Date("2014/1/10 18:20");
        Date date2 = new Date("2014/1/11 3:5");
        long temp = date2.getTime() - date.getTime();    //相差毫秒数
        long hours = temp / 1000 / 3600;                //相差小时数
        long temp2 = temp % (1000 * 3600);
        long mins = temp2 / 1000 / 60;                    //相差分钟数
        System.out.println("date2 与 date 相差" + hours + "小时"+ mins + "分钟");




举报

相关推荐

0 条评论