I want to countdown date and hours and refresh it every 5minutes. When I use setInterval and setTime to 300000ms(5min) my countdown window showing after 5minutes. How can I do it display when I load a page and refresh every 5min? Here is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript</title>
<script>
let deadline = new Date("December 20, 2022, 00:00:00").getTime();
setInterval(function() {
let today = new Date().getTime();
let difference = deadline - today;
let daycount = Math.ceil(difference / (1000 * 60 * 60 * 24));
let hourcount = Math.ceil((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
document.getElementById("count").innerHTML = daycount + " Days " + "and " + hourcount + " Hours " + "hours remain to 00:00, 20th December 2022.";
}, 300000);
</script>
</head>
<body>
<div id="count">
</div>
</body>
</html>