Show Formatted Date

  • Javascript - May 18, 2016

This snippet allows you to display the current date in numbers on your webpage.


<script type="text/javascript">
  function showDate() {
    var d = new Date();
    var current_date = d.getDate();
    var current_month = d.getMonth() + 1; //January is 0
    var current_year = d.getFullYear();
    document.write(current_date + "/" + current_month + "/" + current_year);
  }
</script>

And when you want the date printing out add:

<script type="text/javascript">
  showDate();
</script>

Which outputs:

 

Comments