[英]Android time interval percentage
I have three date objects - startDate, endDate, currentDate. 我有三个日期对象 - 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.
我想知道currentDate代表(x)的百分比,如果currentDate在startDate和endDate之间。
Thank you! 谢谢!
You can calculate the percentage by using .getTime()
on each date: 您可以在每个日期使用
.getTime()
来计算百分比:
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... 编辑:添加
* 100f
因为它是一个百分比,而不是十进制...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.