The Date object lets you work with dates (years, months, days, hours, minutes, seconds, and milliseconds). A JavaScript date can be written as a string:
or as a number (Dates written as numbers, specifies the number of milliseconds since January 1, 1970, 00:00:00. - the "epoch date" when the time started for Unix computers):
In this example below, a script will display the date inside a <p> element with id="demo". This script assigns the value of Date() to the content (innerHTML) of that particular element:
HTML file: | Displayed by browser: |
---|---|
<body>
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = Date(); </script> </body> |