title: Automatic time input on form Javascript
body: <p>Hi everyone I'm new to coding and when creating a form that has current date /  time input I set around looking to find a way to have this area of the form automatic.</p>
  
  <p>I found this piece of javascript on here and it's working great for the date input</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   function SetDate()
   {
   var date = new Date();
  
   var day = date.getDate();
   var month = date.getMonth() + 1;
   var year = date.getFullYear();
  
   if (month &lt; 10) month = "0" + month;
   if (day &lt; 10) day = "0" + day;
  
   var today = year + "-" + month + "-" + day;
  
  
   document.getElementById('date').value = today;
   }
   &lt;/script&gt;
  
   &lt;body onload="SetDate();"&gt; 
  </code></pre>
  
  <p>I have sat for countless hours trying to re write this code to automatically input the time but not having much luck, I'm not just looking for someone to type it for me and it to work as I'm genuinely trying to learn so if anyone can point me out where im going wrong here is the piece of code I'm trying to make work for hours / minutes based on the other persons code</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function SetDate()
  {
  var date = new Date();
  
  var hours = date.getHours();
  var mins = date.getMinutes();
  
  
  if (hours &lt; 10) hours = "0" + hours;
  if (mins &lt; 10) mins = "0" + mins;
  
  var time = hours + "-" + mins + "-" + day;
  
  
  document.getElementById('date').value = time;
  }
  &lt;/script&gt;
  
  &lt;body onload="SetDate();"&gt; 
  </code></pre>
  
  <p>I have also just noticed that when I have this code on the page the working automatic Date <strong>stops</strong> working </p>
  
  <p>Any help will be appreciated whole heartedly</p>