Android时间间隔百分比

3
我有三个日期对象 - startDate,endDate,currentDate。它们代表时间间隔的开始/结束和当前日期。如果当前日期在startDate和endDate之间,则我想知道当前日期占时间间隔的百分比(x)。 enter image description here 谢谢!
1个回答

4
您可以通过对每个日期使用 .getTime() 来计算百分比:
double start = (double)StartDate.getTime();
double end = (double)EndDate.getTime();
double cur = (double)CurrentDate.getTime();

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

编辑:由于这是一个百分比而不是小数,因此添加了* 100f...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接