计算两个date类型的时间差

时间:2023-03-10 06:52:04
计算两个date类型的时间差

//两个时间之间分钟差

public static int compareDate(Date d1, Date d2) {
        // TODO Auto-generated method stub
        long dif = d1.getTime() - d2.getTime();
        long day= dif /(24*60*60*1000);
        long hour=( dif /(60*60*1000)-day*24);
        long min=(( dif /(60*1000))-day*24*60-hour*60);
        long allMIN = hour*24+min;
        return Integer.parseInt(String.valueOf(allMIN));
}