获取两个JavaScript日期之间的时间百分比 [英] Get the percent of time elapsed between two javascript dates

查看:598
本文介绍了获取两个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?

推荐答案

示例: http://jsfiddle.net/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:

示例: http://jsfiddle.net/FLaJM/3/

alert( Math.round(((end - start) * 100 ) / today) + '%' );

这篇关于获取两个JavaScript日期之间的时间百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆