ISO Dates: Year Only

ISO 8601 dates can be written without month and day (YYYY). An example of using only the year will still output a complete date:

   var d = new Date("2015");

HTML file: Displayed by browser:
<body>
<h4>Example of only the year:</h4>
<p id="demo"></p>
<script>
var d = new Date("2015");
document.getElementById("demo").innerHTML = d;
</script>
</body>

Example of only the year:

This would show the first day of the year (January 1) but because of your timezone difference of 8 hours, this shows 8 hours earlier, hence December 31 of the previous year.

BackTable of ContentsNext