This HTML file calculate the difference in days between the current date and a selected date as long as it is later than today.
The final output shows how many days there are between the two dates, but I can't convert it from long to int.
Can anyone solve this problem?
here the codes:
<!DOCTYPE html>
<html>
<head>
<title>Calcolo distanza</title>
</head>
<body onload="myFunction()">
<p> Data corrente </p>
<button type="button" id="myBtn"></button>
<p> Scegli la data </p>
<input type="date" id="dataCorrente">
<input type="submit" onclick="calcola()">
<br>
<p id="Risultato"> </p>
</body>
<script>
var d= new Date();
function myFunction(){
console.log("onload()");
console.log(d);
document.getElementById("myBtn").innerHTML=d.toDateString();
}
function calcola(){
var input = document.getElementById("dataCorrente").value;
if(input!=null){
var dat=new Date();
dat.setHours(0);
dat.setMinutes(0);
dat.setSeconds(0);
var data = new Date(input);
var mill1=dat.getTime();
var mill2=data.getTime();
if(mill2>mill1){
mill2=mill2-mill1;
var ris=mill2/86400000;
document.getElementById("Risultato").innerHTML=ris;
}
else{
document.getElementById("Risultato").innerHTML="La data deve essere maggiore di quella corrente";
}
}
else{
console.log("input=null");
document.getElementById("Risultato").innerHTML="Data non inserita";
}
}
</script>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…