I want to set default time in this datetimepicker as 00:01
for the current date. Anyone tried that before? Having a tough time with it. It Seems simple.
$('#startdatetime-from').datetimepicker({ language: 'en', format: 'yyyy-MM-dd hh:mm' });
I need to use setDate
, but I'm not sure how. I checked their code, but did not find a parameter for that.
Syntax: $(". selector"). datepicker( {defaultDate:"+6"} );
The JavaScript DateTime Picker is a lightweight and mobile-friendly control that allows end users to enter or select date and time values from a pop-up calendar and drop-down time list. It provides month, year, and decade views for quick navigation to the desired date.
Then call datepicker on elements with that class with your default configuration: $('. my-datepicker'). datepicker({ dateFormat: 'yy-mm-dd' });
You can open Time Picker by clicking on another element. If you want to do this, you have to add . time-picker-opener class and data-open="TimePickerID" HTML data-* Attribute on opening element.
Set a default input value as per this GitHub issue.
HTML
<input type="text" id="datetimepicker-input"></input>
jQuery
var d = new Date(); var month = d.getMonth()+1; var day = d.getDate(); var output = d.getFullYear() + '/' + (month<10 ? '0' : '') + month + '/' + (day<10 ? '0' : '') + day; $("#datetimepicker-input").val(output + " 00:01:00");
jsFiddle
JavaScript date source
EDIT - setLocalDate/setDate
var d = new Date(); var month = d.getMonth(); var day = d.getDate(); var year = d.getFullYear(); $('#startdatetime-from').datetimepicker({ language: 'en', format: 'yyyy-MM-dd hh:mm' }); $("#startdatetime-from").data('DateTimePicker').setLocalDate(new Date(year, month, day, 00, 01));
jsFiddle
None of the above worked for me, however I had success setting the default at time of instantiation.
JQuery
<script type="text/javascript"> $(function () { var dateNow = new Date(); $('#datetimepicker').datetimepicker({ defaultDate:dateNow }); }); </script>
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