获取两个JavaScript日期之间的时间百分比

编程入门 行业动态 更新时间:2024-10-12 10:29:22
本文介绍了获取两个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日期之间的时间百分比

本文发布于:2023-11-29 11:36:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:百分比   两个   日期   时间   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!