- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 Flatpickr 使用以下实例化代码。
$("#entry_date_time").flatpickr({
enableTime: true,
altInput: true,
defaultDate: moment().format("YYYY-MM-DD HH:MM:SS"),
dateFormat: "YYYY-MM-DD HH:MM:SS",
minuteIncrement: 1
});
我遇到的问题是 moment().format("YYYY-MM-DD HH:MM:SS");
给了我正确的数据,但是 的输出$("#entry_date_time").val()
等于
2017201720172017-JanJan-SatSat 0000:JanJan:0000
而不是我提供的预期格式。
任何关于可能导致此问题的想法都很好,感谢您的帮助!
最佳答案
Flatpickr 有自己的 formating tokens与 moment 支持的不同。但好处是您可以使用 parseDate
和 formatDate
配置选项来支持自定义格式标记。
/* A custom datestring parser */
parseDate: (date: string, format: string) => Date;
/* Allows using a custom date formatting function instead of the built-in. Generally unnecessary. */
formatDate: (date: Date, format: string, locale: Locale) => string;
带有 moment.js 兼容 token 的示例 https://jsfiddle.net/armujahid/pwqhznj0/
const fp = flatpickr(".date", {
altInput: true,
dateFormat: "YYYY-MM-DD",
altFormat: "DD-MM-YYYY",
allowInput: true,
parseDate: (datestr, format) => {
return moment(datestr, format, true).toDate();
},
formatDate: (date, format, locale) => {
// locale can also be used
return moment(date).format(format);
}
});
引用: 我在 https://github.com/flatpickr/flatpickr/issues/1549#issuecomment-537939826 的评论
更新:此代码段也已添加到 official docs 中
关于date - Flatpickr 和 Moment.js 意外的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43967298/
我正在使用 flatpickr 来设置日期, onChange: function(selectedDates, dateStr, instance) { var myDate = selec
这可能是一个基本问题,但我正在努力。本质上,我有一个 livewire 组件,用于更新用户输入的一系列航类信息。每当组件被重新渲染时, flatpickr 功能就会完全停止工作。我认为这是因为在该字段
当我打开然后关闭 Flatpickr 实例而不选择日期时,它会将其设置为今天的日期。如何防止这种行为?当用户未设置时,我需要日期输入保持为空。 Flatpickr 实例用 React-Flatpick
我正在使用平面选择器,输入的日期如下: 01/02/1991 (Day 1 / Month Feb / Year 1991. 但是,当我添加 Flatpickr 类时,它将日期转换为: 02/01/1
我正在使用 flatpikr https://flatpickr.js.org/我希望在出站(仅日期)选择器的关闭事件中,将返回选择器的初始日期设置为第一个选择器中选择的相同日期。我编写的这段代码可以
我正在使用 Flatpickr满足我的日历需求。它提供了一个带有箭头的输入字段来更改年份。 我需要在日历中有一个下拉列表,以便我可以从该下拉列表中选择一年,然后日历指向那一年。 我动态地给日历元素一个
我正在使用 Flatpickr满足我的日历需求。它提供了一个带有箭头的输入字段来更改年份。 我需要在日历中有一个下拉列表,以便我可以从该下拉列表中选择一年,然后日历指向那一年。 我动态地给日历元素一个
我在我的应用程序上使用“flatpickr”作为日期时间选择器。此日期选择器允许选择多个日期,但在阅读文档后,我找不到任何方法来限制所选日期的最大数量。 Jquery: $('#gig_date_mu
我有以下 html: @Html.LabelFor(x => x.StartDate) @Html.TextBoxFor(m => m.StartDate, "{0:dd-MM-yy
我正在尝试使用 Jquery 实现 flatpickr。到目前为止一切顺利。 我有以下代码,它确实有效: flatpickr("#booking_start", {}); flatpickr("#bo
我有一些使用 flatpickr 日历实例的 HTML。我想做的是在单击随附的跨度时仅打开特定的日历实例。 附带的 Javascript 是
我正在使用这个加载 flatpickr: jQuery(document).ready(function($){ $('#Mydatetime').flatpickr({ a
我开始使用 flatpickr (从 xdsoft datetimepicker 开始,似乎不再积极维护)并希望实现滚动行为,就像 xdsoft 的 datetimepicker 一样,即允许使用鼠标
我正在使用“angularx-flatpickr”以 Angular 形式选择日期。当我点击输入区域然后弹出月份 View 时出现但所有日期都被禁用。 在我的 html 文件中, 我将这个
转载链接: https://jsfiddle.net/isaporto/hav7pqs5/ HTML: Click here JS: document.querySelector('button
我的任务是让用户选择一个日期(它在输入框中正常显示)。创建一个包含年份的新变量,但根据需要使用提供的日期中的一些逻辑来更改它。 我不知道我是否只需要使用提供的 .selectedDates 日期数组,
我目前正在使用 vue-flatpickr-component创建更好的日期输入字段。现在我有一个“onClose()”方法(参见下面的代码)来检查输入的日期是否有效。 我删除了大部分代码以使其更具可
我现在有一个范围日期选择器。 我想重复使用这些日期,但无法为所有场景选择它们。我尝试了下面的代码,如果所选日期在同一个月,该代码效果很好。但我的问题是,如果日期跨越多个月,这段代码将不起作用。 $(
如何在 flatpickr 中设置 maxDate? $("#date-picker").flatpickr("minDate", "2019-7-12"); 但是它不起作用。 最佳答案 尝试使用o
如何在 flatpickr 中设置 maxDate? $("#date-picker").flatpickr("minDate", "2019-7-12"); 但是它不起作用。 最佳答案 尝试使用o
我是一名优秀的程序员,十分优秀!