0

I have a small problem. I have a form where I wish the time were to be written automatically, but I do not know how to do. I tried with:

<input type="time"/> 

but the time is not inserted automatically. Does anybody know how to help me? Thanks!

Andrea php
  • 63
  • 2
  • 8

3 Answers3

0

The topic has been already discussed here, use the Javascript Date() object. A description can be found on the MDN website.

Community
  • 1
  • 1
Christian
  • 4,902
  • 4
  • 24
  • 42
0

The time type is not fully compatible yet, regardless if you want it to read the current date/time as of the time of execution you must populate the field from javascript.

<input type="time" id="time"> 
<script>
document.getElementById("time").value = Date();
</script>
Wobbles
  • 3,033
  • 1
  • 25
  • 51
0

Perhaps:

<body>
   time: <input type="time" id='now'/>  
   <script>document.getElementById('now').value = Date().toString();</script>
</body>

Use toDateString() instead of toString() if you only want the date.

manuBriot
  • 2,755
  • 13
  • 21