Reputation: 5182
I have three date objects - startDate, endDate, currentDate. They represent the start/end of a time interval, and the curent date. I would like to know what percentage does the currentDate represents (x), if currentDate is bewtween the startDate and endDate.
Thank you!
Upvotes: 3
Views: 829
Reputation: 6181
You can calculate the percentage by using .getTime()
on each date:
double start = (double)StartDate.getTime();
double end = (double)EndDate.getTime();
double cur = (double)CurrentDate.getTime();
double percent = ((cur - start) / (end - start)) * 100f;
EDIT: added * 100f
due to it being a percentage, not decimal...
Upvotes: 4