You can use this code snippet. I also added it to jsfiddle
and added type-safer comments, so make sure to check out the fiddle.
If you're using jQuery, call it within your ready function. Otherwise you could use plain JavaScript to update the value of your field.
$(document).ready(function(){
var d = new Date();
var formatted_time = time_format(d);
$('#yourTimeField').text(formatted_time);
});
Add these two methods to your script (you could also paste it in a single file, like it is in the jsfiddle code snippet):
function time_format(d) {
hours = format_two_digits(d.getHours());
minutes = format_two_digits(d.getMinutes());
seconds = format_two_digits(d.getSeconds());
return hours + ":" + minutes + ":" + seconds;
}
function format_two_digits(n) {
return n < 10 ? '0' + n : n;
}
That's it :) Hope it helps :)