Search This Blog

Friday, 10 March 2017

JavaScript::Show Formatted Date

Show Formatted Date

Head:
<script type="text/javascript">
  function showDate() {
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //months are zero based
    var curr_year = d.getFullYear();
    document.write(curr_date + "-" + curr_month + "-" + curr_year);
  }
</script>
Body:
<script type="text/javascript">showDate();</script>

This snippet will allow you to display the current date anywhere on your webpage and does not need to be updated. Simply put it in place and forget about it.

No comments:

Post a Comment