如何从 flatpicker 开始和结束日期?

How to get from and to dates from flatpicker?

我需要使用 flatpicker

获得 fromto

这是设置:

$(".flatpickr").flatpickr({
    mode: "range",
    disableMobile: "true",
    altInput: true,
    altFormat: "d/m/Y",
    dateFormat: "d/m/Y",
    enable: [{
        from: new Date(dataSetCopy[0]),
        to: new Date(dataSetCopy[dataSetCopy.length - 1])
    }],..

关闭时我需要获取每个日期并将它们保存到变量名称中,例如:

var dateStart = "12/3/2020";
var dateEnd = "31/3/2020";

我试过了:

onClose: function(dateObj, dateStr, selectedDates) {
    $('body').removeClass('preventscroll');
    var dateStart = new Date(dateObj[0]);
    var dateEnd = new Date(dateObj[1]);
    dateStart.setHours(0, 0, 0, 0);
    dateEnd.setHours(0, 0, 0, 0);

但是我明白了

Tue Mar 31 2020 00:00:00 GMT+0200 (Ora legale dell’Europa centrale)

试图检查 the docs 但我不明白如何

您可以使用formatDate() method from the flatpickr instance

$(".flatpickr").flatpickr({
  mode: "range",
  disableMobile: "true",
  altInput: true,
  altFormat: "d/m/Y",
  dateFormat: "d/m/Y",
  onClose: function(selectedDates, dateStr, instance) {
    var dateStart = instance.formatDate(selectedDates[0], "d/m/Y");
    var dateEnd = instance.formatDate(selectedDates[1], "d/m/Y");

    console.log(dateStart)
    console.log(dateEnd)
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>

<input class="flatpickr">