Jquery time difference in hours from two fields

前端 未结 4 1460
小蘑菇
小蘑菇 2020-11-28 14:36

I have two fields in my form where users select an input time (start_time, end_time) I would like to, on the change of these fields, recalcuate the value for another field.<

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 15:10

       var start = '5:30';
       var end = '7:50';
       s = start.split(':');
       e = end.split(':');
       min = e[1]-s[1];
       hour_carry = 0;
       if(min < 0){
           min += 60;
           hour_carry += 1;
       }
       hour = e[0]-s[0]-hour_carry;
       min = ((min/60)*100).toString()
       diff = hour + ":" + min.substring(0,2);
       alert(diff);
    

提交回复
热议问题