简体   繁体   English

Pikaday日历日期格式不起作用

[英]Pikaday calendar date format not working

I'm using the Pikaday calendar library but the date format seems to be being ignored. 我正在使用Pikaday日历库,但日期格式似乎被忽略了。 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'. 这将以“2017年5月25日星期四”的格式输出日期,我需要格式为“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. 根据Pikaday文档,您必须引用Moments.js以使自定义日期格式设置工作。

From the docs : 来自文档

format: the default output format for .toString() and field value (requires Moment.js for custom formatting) format:.toString()的默认输出格式和字段值(需要Moment.js进行自定义格式化)

Make sure to reference the Moments.js library before Pikaday. 确保在Pikaday 之前引用Moments.js库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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