JAVA-计算两个日期之间相差的天数

xiaoxiao2021-08-29  1.2K+

/**      * 计算两个日期之间相差的天数      * @param date1      * @param date2      * @return      */     public static int daysBetween(Date date1,Date date2){              Calendar cal = Calendar.getInstance();              cal.setTime(date1);              long time1 = cal.getTimeInMillis();                           cal.setTime(date2);              long time2 = cal.getTimeInMillis();                   long between_days=(time2-time1)/(1000*3600*24);     

        return Integer.parseInt(String.valueOf(between_days));                 }

转载请注明原文地址: https://www.6miu.com/read-4823580.html

最新回复(0)