Skip to content

Auto update date and time [closed]

I would like to make the current date and time in a div element in html update automatically. Is there a way I can do this? I do know that I can update it by clicking on a button.


You can do this:

<!DOCTYPE html>
<title>Page Title</title>
<div id="time"></div>
    setInterval(function(){ document.getElementById('time').innerText = new Date()}, 1000);