2011-10-24 53 views
3

我有三个日期对象 - startDate,endDate,currentDate。它们代表时间间隔的开始/结束,以及预期日期。我想知道currentDate代表的是什么百分比(x),如果currentDate在startDate和endDate之间。 enter image description hereAndroid时间间隔百分比

谢谢!

回答

5

您可以通过在每个日期使用.getTime()计算百分比:

double start = (double)StartDate.getTime(); 
double end = (double)EndDate.getTime(); 
double cur = (double)CurrentDate.getTime(); 

double percent = ((cur - start)/(end - start)) * 100f; 

编辑:添加* 100f,由于它是一个百分比,而不是十进制...