1
votes

The datepicker included i chrome browser allow the users to select dates. The user will see the date in a format and the input value will be always in the format: "YYYY-MM-DD".

I want the same behavior when using bootstrap-datetimepicker.

If I specify the format when initializing the plugin like this

$('.date-picker').datetimepicker({
    format: 'DD/MM/YYYY'
});

when I get the input value it's in the same format, 'DD/MM/YYYY'. I want it to be in the standard format which is "YYYY-MM-DD".

Same thing when I specify the locale.

$('.date-picker').datetimepicker({
    locale: 'fr'
});

Can any one help me?

Thank you very much

1

1 Answers

0
votes

When you initialize the bootstrap-datetimepicker plugin you can choose the format you prefer, so you can have:

$('.date-picker').datetimepicker({
    format: 'YYYY-MM-DD'
});

Then the input value will be in the format 'YYYY-MM-DD'.

If you need to display the date in a given format and then convert it in another one you can use Moment format function. For example:

$('#yourpickerid').datetimepicker({
    format: 'DD/MM/YYYY'
});

function getPickerValue(){
    // Get picker date
    var val = $('#yourpickerid').data("DateTimePicker").date();
    // Convert date to given format
    var dateStr = val.format('YYYY-MM-DD');
    return dateStr;
}