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?
I wrote a jQuery method that sets the current UTC time. It's useful for initializing datetime
and datetime-local
input fields.
Here's how you would use it to initialize a field.
$('input[type="datetime"]').setNow();
Or pass an argument of true
to only set fields with no value.
$('input[type="datetime"]').setNow(true);