javascriptpikaday

Pikaday calendar date format not working


I'm using the Pikaday calendar library but the date format seems to be being ignored. I have this code:

<script>
var picker = new Pikaday(
{
    field: document.getElementById('dayDate'),
    firstDay: 1,
    minDate: new Date(2017, 0, 1),
    maxDate: new Date(2020, 12, 31),
    yearRange: [2017, 2020],
    format: 'YYYY-MM-DD',
    bound: false,
    container: document.getElementById('date-container'),
});
</script>

This outputs the date in this format 'Thu May 25 2017' I need it to be in the format '2017-05-25'. What am I doing wrong?


Solution

  • Based on the Pikaday documentation, you have to reference Moments.js to make the custom date formatting work.

    From the docs:

    format: the default output format for .toString() and field value (requires Moment.js for custom formatting)

    Make sure to reference the Moments.js library before Pikaday.