drhib62644 2017-07-28 11:24
浏览 168

计算两个日期之间的百分比

I want to calculate between two dates difference to percent. Only not date, hours needed to scale. Example:

22-08-2017 09:00 start date,
30.09.2017 22:00 finish date,

The today date is 01.09.2017. When I look to system today, the application show to me "%47 percent completed" I want to this.

  • 写回答

5条回答 默认 最新

  • dtudj42064 2017-07-28 11:32
    关注

    function getpercent(){
    var strt = new Date(document.getElementById('start').value).getTime();
    
    var end = new Date(document.getElementById('end').value).getTime();
    
    var current = new Date(document.getElementById('current').value).getTime();
    
    var completed = ((current - strt) / (end - strt)) * 100;
    document.getElementById('percent').innerHTML = completed+"%";
     }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <p>start <input id="start" type="date" /></p>
    <p>end <input id="end" type="date" /></p>
    <p>current <input id="current" type="date" /></p>
    <p>percent   <span id="percent"></span></p>
    <button onclick="getpercent()">get percent</button>

    new Date() will take a date string and turn it into unix standard time as seconds.

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序