Creating Date Objects

The Date object lets us work with dates. A date consists of a year, a month, a day, an hour, a minute, a second, and milliseconds. Date objects are created with the new Date() constructor. There are 4 ways of initiating a date:

   new Date()
   new Date(milliseconds)
   new Date(dateString)
   new Date(year, month, day, hours, minutes, seconds, milliseconds)

HTML file: Displayed by browser:
<body>
<p id="demo"></p>

<script>
var d = new Date();
document.getElementById("demo").innerHTML = d;
</script>
</body>

This example is the exact same result given on the previous webpage. The difference is that this one used a variable.

BackTable of ContentsNext