The examples in this article describe a method of days between Java fetching dates. Share to everyone for your reference. The implementation methods are as follows:
private int Daysbetween (date now, date returndate) {
Calendar Cnow = Calendar.getinstance ();
Calendar creturndate = Calendar.getinstance ();
Cnow.settime (now);
Creturndate.settime (returndate);
Settimetomidnight (Cnow);
Settimetomidnight (creturndate);
Long todayms = Cnow.gettimeinmillis ();
Long Returnms = Creturndate.gettimeinmillis ();
Long intervalms = TODAYMS-RETURNMS;
Return Millisecondstodays (Intervalms);
}
private int millisecondstodays (long intervalms) {return
(int) (INTERVALMS/1000 * 86400));
private void Settimetomidnight (Calendar calendar) {
calendar.set (calendar.hour_of_day, 0);
Calendar.set (calendar.minute, 0);
Calendar.set (Calendar.second, 0);
}
I hope this article will help you with your Java programming.