Pierre Olivier Tran
Pierre Olivier Tran

Reputation: 1879

Set moments.js default to specific datetime

I'm using moments.js to set an input to current datetime. It works just fine for days, but I'd like to use the same for hours and minutes.

So far, I've been using this:

    var today = moment();
    var tomorrow = today.add(1, 'days');

    $($selector).find('.datetimepicker').datetimepicker({
        locale: global.locale,
        minDate: date,
        stepping: 15,
        defaultDate: moment(tomorrow).format("YYYY-MM-DD")
    });

So that my input is set to tomorrow. Unfortunately, it sets time to 12AM. Is it possible to set time to current one, and day to tomorrow ?

Upvotes: 0

Views: 1822

Answers (1)

HNA
HNA

Reputation: 307

You just need to specify hh:mm in your output format.

You do not need to create a new moment out of your "tomorrow" object to format it either.

var today = moment();
var tomorrow = today.add(1, 'days');

$($selector).find('.datetimepicker').datetimepicker({
    locale: global.locale,
    minDate: date,
    stepping: 15,
    defaultDate: tomorrow.format("YYYY-MM-DD hh:mm")
});

Here is a working fiddle example: http://jsfiddle.net/vnbcgau2/

Upvotes: 2

Related Questions