How to set the current date when HTML document (page) has been loaded with JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>

<head>  
</head>
  
<body onload="WriteDate()">

<h2 id="h1-id"></h2>


<script>        

function WriteDate() 
{
  document.getElementById("h1-id").innerHTML = "Today: " + Date();
}

/*
run:

Today: Thu Aug 27 2015 11:20:30 GMT+0300 (Jerusalem Standard Time)
  
*/

</script>

</body>
</html>

 



answered Aug 27, 2015 by avibootz
...