public static void test(String endDate,String newDate) throws ParseException {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 *60;
long nm = 1000 * 60;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d1 = df.parse(endDate);
Date d2 = df.parse(newDate);
long diff = d1.getTime() - d2.getTime();
long day = diff/nd;
long hour = diff/nh;
long minute = diff/nm;
log.info("相差的天数为:"+day);
log.info("相差的小时为:"+hour);
log.info("相差的分钟数为:"+minute);
}
java 计算时间差
最新推荐文章于 2024-09-15 20:27:11 发布