var
dt1 =
"2009-11-5 10:30"
var
dt2 =
"2009-11-8 9:20"
function
getHoursDiff(dt1,dt2) {
if
(
typeof
(dt1)==
"string"
) {
dt1=
new
Date(dt1.replace(/-/,
'/'
));
dt2=
new
Date(dt2.replace(/-/,
'/'
));
}
var
res=dt2-dt1;
if
(isNaN(res))
throw
Error(
"invalid dates arguments"
);
return
res/(1000*60*60);
}
var
re=getHoursDiff(dt1,dt2);
var
h=parseInt(re);
var
m=parseInt((re-h)*60);
alert(
"时间相隔"
+h+
"小时"
+m+
"分钟"
);