计算一个日期到今天相差的天数

Date enrollDate = inter.getEnrollDate();     //可以自己创个时间节点
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if (enrollDate != null) {
    String end = sdf.format(enrollDate);
    String time = sdf.format(today);
    try {
        enrollDate = sdf.parse(end);
        today = sdf.parse(time);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

long enrollDays = (today.getTime() - enrollDate.getTime()) / (24 * 60 * 60 * 1000);

你可能感兴趣的:(Java)