[英]Find the lapse of time
I'm trying to get the time lapse between 2 diferent hours.... 我正在尝试让时间间隔在2个不同小时之间。
function time()
{
var startime=(document.getElementById("horaentrada").value);
var endtime=(document.getElementById("horasaida").value);
document.getElementById("total_horas").value = (endtime-startime);
}
the idea is to fill a html input "total_horas" with the result. 这个想法是用结果填充html输入“ total_horas”。 The function is triggered by an onchange event.
该函数由onchange事件触发。 The entry format is "HH:mm:ss", by instance 9:35:22.
输入格式为“ HH:mm:ss”,例如9:35:22。
I've tried a lot of things, but, no one works I get NaN. 我已经尝试了很多方法,但是没人能得到NaN。
Try this: 尝试这个:
function time()
{
var startime=(document.getElementById("horaentrada").value);
var endtime=(document.getElementById("horasaida").value);
document.getElementById("total_horas").value= (parseFloat(endtime,10)-parseFloat(startime, 10));
}
Also, make sure to run the function after the dom is loaded. 另外,请确保在加载dom后运行该功能。
Fiddle: http://jsfiddle.net/LnLdB/2/ . 小提琴: http : //jsfiddle.net/LnLdB/2/ 。 Just be gentle with the stuff you input in the boxes.
请对输入框中的内容保持温和。
EDIT: Here is an updated fiddle, using moment.js. 编辑:这是一个更新的小提琴,使用moment.js。 It subtracts hours in the format "HH:mm:ss": http://jsfiddle.net/LnLdB/13/
它减去“ HH:mm:ss”格式的小时: http : //jsfiddle.net/LnLdB/13/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.