Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default time in bootstrap-datetimepicker

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.

like image 445
change Avatar asked Aug 01 '13 22:08

change


People also ask

How do I set the default time on Datepicker?

Syntax: $(". selector"). datepicker( {defaultDate:"+6"} );

What is DateTimePicker (); in JS?

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.

How do I change the default date format in Datepicker?

Then call datepicker on elements with that class with your default configuration: $('. my-datepicker'). datepicker({ dateFormat: 'yy-mm-dd' });

How do I use Bootstrap time Picker?

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.


2 Answers

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

like image 29
Sara Avatar answered Sep 21 '22 10:09

Sara


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> 
like image 173
Nicholas Hamilton Avatar answered Sep 22 '22 10:09

Nicholas Hamilton