I am trying to use javascript and/or jquery to auto populate the time in an type time field; not the date. It auto populates fine. However, i am trying to have it auto populate the current time rather than a specified time. (e.g."17:40:11")
How do I get the current time from javascript or jquery and auto populate it in an input time field?
Below, pasted is my code and the following error I am getting using Javascript.
Ive tried using jquery with new Date($.now()); but I get a similar error but my time is a bunch of numbers(e.g. 123435334)
Thanks for any help.
HTML
<input type="time" value="" />
javascript
$(document).ready(function myTimer() {
var now = new Date(Date.now());
var f = now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
$("input[type=time]").val(f);
})
error
jquery.js:7373 :
The specified value '7:13:40' does not conform to the required format. The format is 'HH:mm', 'HH:mm:ss' or 'HH:mm:ss.SSS' where HH is 00-23, mm is 00-59, ss is 00-59, and SSS is 000-999.