Vlad Bezden Vlad Bezden - 1 year ago 178
HTML Question

How to set datetime on datetime-local via jQuery

I have datetime-local html control on my form and I need to set date and time on it dynamically via JS or jQuery. How can I do it?

<input type="datetime-local" id="publishDate" required/>

I tried

$("#publishDate").val("2013-3-18 13:00");
$("#publishDate").val(new Date().toLocalString());

but nothing worked.

Thanks in advance.

Answer Source

This would do the trick


You need to use 2 digits for the month to make your sample work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download