Set date in bootstrap datetimepicker input

Set date in bootstrap datetimepicker input

I used the datetimepicker from:
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:

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

I tried
date: function() { return new Date(1434544649384); }

Where 1434544649384 is a timestamp.
But it doesn’t work and doesn’t update input text/value…


Solution 1:

The correct syntax is :

    date: new Date(1434544882775)

Solution 2:

quote from

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());

Solution 3:

Had to add, I was able to solve it.

$('#datetimepicker1').data("DateTimePicker").date(moment(new Date ).format('DD/MM/YYYY HH:mm'));

Solution 4:

You want to set a default date value :

var d = $('#datetimepicker1').datetimepicker({
    "defaultDate":new Date()

Solution 5:

For me although I managed to change the date, it also changed the format incorrectly. When I applied the format separately it then worked as expected:

var d = $('#datetimepicker1').({ date: moment(), format: $scope.userDateFormatMoment });

Solution 6:

If you are looking to set the date of your datetimepicker, use the defaultDate option. From the documentation:

Related:  What is the unicode character for the close symbol used by Twitter bootstrap?

defaultDate: Sets the picker default date/time. Default: false. Accepts: date, moment, string.

Your options would look like:

    defaultDate: new Date(1434544649384)