简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM