I am trying to calculate the clock between two points.
Below I am, but this code does not work in two ways.
1). I need .Hoursto output time in decimal format.
(for example, one and half an hour should output 1.5 and 15 minutes, should be 0.25).
2). The calculation does not currently process time values time.
(e.g., from 23:00 to 2:00 should be equal 3and NOT -21 in the present).
HTML
<input class="Time1" value="10:00" />
<input class="Time2" value="12:00" />
<input class="Hours" value="0" />
JQuery
$(function () {
function calculate() {
var hours = parseInt($(".Time2").val().split(':')[0], 10) - parseInt($(".Time1").val().split(':')[0], 10);
$(".Hours").val(hours);
}
$(".Time1,.Time2").change(calculate);
calculate();
});
http://jsfiddle.net/44NCk/
source
share