Java日期差异的天数

Arv*_*han 4 java date

有谁能帮助我Date以有效的方式计算天数方面的差异?

Date nextCollectionDate = dispenseNormal.getDispensing().getNextCollectionDate();
Date currentDate = new Date();
int daysDiff = currentDate - nextCollectionDate;
Run Code Online (Sandbox Code Playgroud)

Shi*_*ine 6

//diff in msec
long diff = currentDate.getTime() - nextCollectionDate.getTime();

//diff in days
long days = diff / (24 * 60 * 60 * 1000);
Run Code Online (Sandbox Code Playgroud)