JavaScript Short Dates

Short dates are most often written with an "MM/DD/YYYY" syntax like this:

   var d = new Date("03/25/2015");

HTML file: Displayed by browser:
<body>
<h4>Example of a short date:</h4>
<p id="demo"></p>
<script>
var d = new Date("03/25/2015");
document.getElementById("demo").innerHTML = d;
</script>
</body>

Example of a short date:

You can use either "/" or "-" as a separator for JavaScript short dates. JavaScript will also accept the "YYYY/MM/DD" syntax. The following declarations will return the same date formats, as shown in the HTML/Browser example above:

   variable = new Date("03-25-2015");
   variable = new Date("2015/03/25");

Good habit Remember, the month is always written before day in all short date and ISO date formats.
Back Table of Contents Next