Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set date in bootstrap datetimepicker input

I used the datetimepicker from: http://eonasdan.github.io/bootstrap-datetimepicker/Installing/

There no provide how to use function (date, show, hide, etc) so I don't know how to set the value for input using datetimepicker using date function which says:

date([newDate])

Takes string, Date, moment, null parameter and sets the components model current moment to it.

I tried

$('#datetimepicker2').datetimepicker(
    date: function() { return new Date(1434544649384); }
);

Where 1434544649384 is a timestamp.

But it doesn't work and doesn't update input text/value...

JsFiddle: http://jsfiddle.net/0Ltv25o8/1397/

like image 499
Snake Eyes Avatar asked Jun 17 '15 12:06

Snake Eyes


3 Answers

quote from http://eonasdan.github.io/bootstrap-datetimepicker/Functions/

Note All functions are accessed via the data attribute e.g. $('#datetimepicker').data("DateTimePicker").FUNCTION()

So you can update date like following:

$('#datetimepicker2').data("DateTimePicker").date(new Date());
like image 55
xfdai Avatar answered Oct 17 '22 10:10

xfdai


The correct syntax is :

$('#datetimepicker2').datetimepicker({
    date: new Date(1434544882775)
});
like image 21
Cyril Duchon-Doris Avatar answered Oct 17 '22 10:10

Cyril Duchon-Doris


Had to add, I was able to solve it.

$('#datetimepicker1').datetimepicker({});
$('#datetimepicker1').data("DateTimePicker").date(moment(new Date ).format('DD/MM/YYYY HH:mm'));
like image 17
Sandeep Avatar answered Oct 17 '22 11:10

Sandeep