How can I convert time to decimal number in JavaScript?

后端 未结 4 2247
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 17:43

I\'m too lazy to fill out my time sheet at work by the end at the end of every month, so I\'ve started adding some functions to our PDF form. Acrobat Pro offers to make advanced

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-15 18:24

    Another way ;)

    var aHours = 4.45;
    
    var aHoursInMinutes = (Math.floor(aHours) * 60 )+ ((aHours - Math.floor(aHours)) * 100);
     // 285 minutes;
    
    var afromMinutesToHours = 
    (Math.floor(aHoursInMinutes /60) + ((aHoursInMinutes - (60* Math.floor(aHoursInMinutes /60)))/100));
     // 4.45 hours;
    
    var bHours = 0.33;
    
    var bHoursInMinutes = (Math.floor(bHours) * 60 )+ ((bHours - Math.floor(bHours)) * 100); // 33 minutes;
    
    var bFromMinutesToHours = 
    (Math.floor(bHoursInMinutes / 60) + (( bHoursInMinutes - (60 * Math.floor(bHoursInMinutes / 60)))/100)); // 0.33 hours;
    
    var resultInMinutes = aHoursInMinutes + bHoursInMinutes;
    var resultToHours = 
    (Math.floor(resultInMinutes / 60) + (( resultInMinutes - (60 * Math.floor(resultInMinutes  / 60)))/100)); // 5.18 hours;
    

提交回复
热议问题