[英]Convert from input type date to miliseconds using javascrip?
i'm trying to convert date (from a input type="date") to miliseconds but my output is "NaN, NaN" for some reason.我正在尝试将日期(从输入类型 =“日期”)转换为毫秒,但我的 output 出于某种原因是“NaN,NaN”。
HTML code: HTML 代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Stats</title>
<h1>Stats</h1>
</head>
<body>
<div class="contenedorFechas" for="fechas">
<p>Insert date to promediate temps and humidity</p>
<input type="date" id="fechaUno">
<input type="date" id="fechaDos">
<input type ="button" id="btnPetDatos" value="Solcitar">
<p id="pRespuesta">...</p>
</div>
</body>
<script src="metodosJS.js" type="text/javascript"></script>
</html>
Javascript: Javascript:
document.getElementById("btnPetDatos").onclick = function (){
var auxUno = new Date(document.getElementById("fechaUno").value);
var auxDos = new Date(document.getElementById("fechaDos").value);
var fechaUno = auxUno.getMilliseconds();
var fechaDos = auxDos.getMilliseconds();
var Parametros = [fechaUno,fechaDos];
document.getElementById("pRespuesta").innerHTML = Parametros;
}
You forgot to take value of date elements您忘记获取日期元素的值
document.getElementById("btnPetDatos").onclick = function (){
var auxUno = new Date(document.getElementById("fechaUno").value);
var auxDos = new Date(document.getElementById("fechaDos").value);
var fechaUno = auxUno.getMilliseconds();
var fechaDos = auxDos.getMilliseconds();
var Parametros = [fechaUno,fechaDos];
document.getElementById("pRespuesta").innerHTML = Parametros;
}
And are u sure to use getMilliseconds()
method because u choose time so there is not hour or minute so u will take 0 always.你确定使用
getMilliseconds()
方法吗,因为你选择时间,所以没有小时或分钟,所以你总是取 0。 u can use getTime()
method it return an integer to you.您可以使用
getTime()
方法返回 integer 给您。 So you can use them how you want.因此,您可以随心所欲地使用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.