1. Ingrese la página de códigos a través del F12, y seleccione el elemento por encima de la página a través de la Mayús + Ctrl + C clave. De este modo, se obtiene el valor ID del elemento correspondiente. Pasar
var a1=document.getElementById("ID name").value; // Get the value value via Document.GetElementByID ("ID Name) .value.
2. La fecha y hora que he obtenido aquí está separada, por lo que primero debemos fusionarnos primero. Sin embargo, los datos del tipo de fecha no se pueden combinar directamente y deben convertirse mediante la conversión de datos.
var t1= a1.toString();// Transfer the date type to a string through TOString () to facilitate the merger of the date and time.
For the process of demonstrating the merge, I will directly set two values.
var t1="2017-7-7";
var t2="13:45"
var b1=t1+' '+t2; // Here you need to add a space because if you don't add a result is "2017-7-713: 45"
The data will be together, and the NAN error prompt is easily displayed when the data is calculated below.
3. Calculando la marca de tiempo de las dos veces diferentes, se calcula el número de milisegundos en las dos fechas.
var date1 = new Date(b1);// Date2 and Date1 setting method, here is written
var Difference_In_Time = date2.getTime()-date1.getTime();
var Difference_In_Days = Difference_In_Time / (1000 * 3600 );// Get the number of hours after two days
4. Salida
document.getElementById("ID name of the output location").innerHTML=Difference_In_Days ;
.