JavaScript Date Formatting


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var currentTime = new Date()
  2. var month = ("0" + (currentTime.getMonth() + 1)).slice(-2)
  3. var day = currentTime.getDate()
  4. var year = currentTime.getFullYear()
  5. //insert into form
  6. var frm = document.getElementById('contact-form');
  7. frm.dater.value = (year + "-" + month + "-" + day)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.