I have 4 INPUT fields for month, day, hour, minute.
<input type="text" id="month" name="month" value="" />
<input type="text" id="day" name="day" value="" />
<input type="text" id="hour" name="hour" value="" />
<input type="text" id="minute" name="minute" value="" />
I am trying to get CURRENT time using JS and insert into each field using jQuery.
Can you help me to work out the right code to accomplish this?
$(document).ready(function() {
var now = new Date();
$("#month").val(now.getMonth() + 1); //Months in JS start from 0
$("#day").val(now.getDate());
$("#hour").val(now.getHours());
$("#minute").val(now.getMinutes());
});
See this MDN page for more information on the Date
object.
meh... for what it's worth: http://jsfiddle.net/V3J8c/1
$("#month").val(months[new Date().getMonth()])
$("#day").val(new Date().getDate())
$("#hour").val(new Date().getHours())
$("#minute").val(new Date().getMinutes())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With