可能重复:
在java中计算日期/时间差
我为用户提供了使用日期选择器选择日期的选项。是否有任何内置方法可以用来计算用户选择日期和今天日期的持续时间(以天为单位)。
Date today = new Date(); // the date of today
Date target = new Date(); // the date of when the user picks
long todayEpoch = today.getTime(); // or can use = System.currentTimeMillis();
long targetEpoch = target.getTime();
long daysInMs = targetEpoch - todayEpoch; //days in MS's
//the # of days
float days = (daysInMs/1000/60/60/12);
以毫秒为单位获取两次之间的差异。你可以通过 Java 的 Calendar 类获得 Days。