Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Date difference in terms of days [duplicate]

Tags:

java

date

Could anyone please help me out for calculating Date difference in terms of no of days in an efficient way?

Date nextCollectionDate = dispenseNormal.getDispensing().getNextCollectionDate();
Date currentDate = new Date();
int daysDiff = currentDate - nextCollectionDate;
like image 832
Arvind Chavhan Avatar asked Dec 14 '22 11:12

Arvind Chavhan


1 Answers

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

//diff in days
long days = diff / (24 * 60 * 60 * 1000);
like image 93
Shine Avatar answered Dec 24 '22 17:12

Shine