01.
<input type=
"text"
id=
"txt1"
>
02.
<input type=
"text"
id=
"txt2"
>
03.
<input type=
"text"
id=
"txt3"
>
04.
05.
<script>
06.
function
GetTimeDiff() {
07.
08.
var
txt1 = document.getElementById(
"txt1"
).value;
09.
var
txt2 = document.getElementById(
"txt2"
).value;
10.
11.
start = txt1.split(
":"
);
12.
end
= txt2.split(
":"
);
13.
var
startDate =
new
Date
(0, 0, 0, start[0], start[1], 0);
14.
var
endDate =
new
Date
(0, 0, 0,
end
[0],
end
[1], 0);
15.
var
diff = endDate.getTime() - startDate.getTime();
16.
var
hours = Math.
floor
(diff / 1000 / 60 / 60);
17.
diff -= hours * 1000 * 60 * 60;
18.
var
minutes = Math.
floor
(diff / 1000 / 60);
19.
20.
var
result = (hours < 9 ?
"0"
:
""
) + Math.
abs
(hours) +
":"
+ (minutes < 9 ?
"0"
:
""
) + minutes;
21.
document.getElementById(
"txt3"
).value = result;
22.
23.
}
24.
25.
document.getElementById(
"txt1"
).onchange =
function
(){
26.
GetTimeDiff();
27.
};
28.
document.getElementById(
"txt2"
).onchange =
function
(){
29.
GetTimeDiff();
30.
};
31.
</script>