本文介绍了获取两个JavaScript日期之间的时间百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找一个学年剩下多少天,并将其作为jQuery UI进度条返回。
I'm trying to find how many days are left in a school year and return it as a jQuery UI progressbar.
jQuery UI进度条只需要百分比。在今天的日期之前,我如何找到我在两个提供的日期之间的时间范围内的百分比?
jQuery UI progressbars only take percentages. How can I find the percentage of how far along I am in the timespan between two supplied dates, given today's date?
推荐答案示例: jsfiddle/FLaJM/4/
var start = new Date(2005,0,1), end = new Date(2021,0,1), today = new Date(); alert( Math.round(100-((end - start) * 100 ) / today) + '%' );或如果您想要剩余百分比:
or if you wanted the percentage remaining:
示例: jsfiddle/FLaJM/3/
alert( Math.round(((end - start) * 100 ) / today) + '%' );更多推荐
获取两个JavaScript日期之间的时间百分比
发布评论