How can I convert time to decimal number in JavaScript?

后端 未结 4 2249
佛祖请我去吃肉
佛祖请我去吃肉 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:09

    Separate hours and minutes, divide minutes by 60, add to hours.

    function timeStringToFloat(time) {
      var hoursMinutes = time.split(/[.:]/);
      var hours = parseInt(hoursMinutes[0], 10);
      var minutes = hoursMinutes[1] ? parseInt(hoursMinutes[1], 10) : 0;
      return hours + minutes / 60;
    }
    

提交回复
热议问题