Link to home
Start Free TrialLog in
Avatar of yongsing
yongsing

asked on

Get num days between 2 Calendars

I have two Calendar objects, with their time fields (hour, minute, second, millisecond) all set to zeros. I want to get the days difference between these two objects.

Example:

Calendar 1: 2006-06-26
Calendar 2: 2006-06-27
results: -1

Calendar 1: 2006-06-26
Calendar 2: 2006-06-25
results: 1
Avatar of mukundha_expert
mukundha_expert

Use compareTo() to get the difference in time in Milliseconds,

from this you can get the difference of days,

int time = cal1.compareTo(cal2);

int days = time / 1000*60*60*24

ASKER CERTIFIED SOLUTION
Avatar of mukundha_expert
mukundha_expert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mayank S