Vlad Bezden Vlad Bezden - 5 months ago 55
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.


This would do the trick


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