简体   繁体   English

如何在 js flatpickr 中删除单个数字日期之前的 0?

[英]how to remove 0 before single number date in js flatpickr?

The js code given below:下面给出js代码:

var endDatePicker = flatpickr("#end-date-picker", {
  enableTime: false,
  singleDate: true,
  selectForward: false,
  dateFormat: "M d, Y",
  onChange: function(selectedDates, dateStr, instance) {
    document.getElementById("end-str-date").innerHTML = dateStr;
  }
});

// Set calendar for table field
  
var StartDatePicker = flatpickr("#beg-date-picker", {
  enableTime: false,
  singleDate: true,
  selectForward: false,
  dateFormat: "m/d/Y",
  year: "numeric",
  month: "1-digit",
  day: "1-digit",
  onChange: function(selectedDates, dateStr, instance) {
    document.getElementById("beg-str-date").innerHTML = dateStr;
  }
});

enter image description here在此处输入图像描述

I want to do this format without 0 before single number day/month date.我想在单个数字日/月日期之前不使用 0 来执行此格式。

enter image description here在此处输入图像描述

But it show like that, with zero.但它显示为零。

Just change the format from m/d/Y to n/j/Y .只需将格式从m/d/Y更改为n/j/Y

You can read more about it in the official documentation , but I'll post it here as well:您可以在官方文档中阅读更多相关信息,但我也会在这里发布:

Character特点 Description描述 Example例子
d d Day of the month, 2 digits with leading zeros一个月中的第几天,带前导零的 2 位数字 01 to 31 01至31
D A textual representation of a day一天的文本表示 Mon through Sun周一到周日
l (lowercase 'L') l(小写字母“L”) A full textual representation of the day of the week星期几的完整文本表示 Sunday through Saturday周日至周六
j j Day of the month without leading zeros一个月中没有前导零的日子 1 to 31 1 至 31
J Day of the month without leading zeros and ordinal suffix没有前导零和序号后缀的月份中的第几天 1st, 2nd, to 31st第 1、2、31 名
w w Numeric representation of the day of the week星期几的数字表示 0 (for Sunday) through 6 (for Saturday) 0(周日)到 6(周六)
W W Numeric representation of the week星期的数字表示 0 (first week of the year) through 52 (last week of the year) 0(一年的第一周)到 52(一年的最后一周)
F F A full textual representation of a month一个月的完整文本表示 January through December一月到十二月
m Numeric representation of a month, with leading zero月份的数字表示,前导零 01 through 12 01 到 12
n n Numeric representation of a month, without leading zeros月份的数字表示,没有前导零 1 through 12 1 到 12
M A short textual representation of a month一个月的简短文本表示 Jan through Dec一月到十二月
U ü The number of seconds since the Unix Epoch自 Unix 纪元以来的秒数 1413704993 1413704993
y A two digit representation of a year年份的两位数表示 99 or 03 99 或 03
Y A full numeric representation of a year, 4 digits年份的完整数字表示,4 位数字 1999 or 2003 1999 或 2003
Z Z ISO Date format ISO 日期格式 2017-03-04T01:23:43.000Z 2017-03-04T01:23:43.000Z

Check the working example, as well.还要检查工作示例。

 var endDatePicker = flatpickr("#end-date-picker", { enableTime: false, singleDate: true, selectForward: false, dateFormat: "M d, Y", onChange: function(selectedDates, dateStr, instance) { document.getElementById("end-str-date").innerHTML = dateStr; } }); // Set calendar for table field var StartDatePicker = flatpickr("#beg-date-picker", { enableTime: false, singleDate: true, selectForward: false, dateFormat: "j/n/Y", year: "numeric", month: "1-digit", day: "1-digit", onChange: function(selectedDates, dateStr, instance) { document.getElementById("beg-str-date").innerHTML = dateStr; } });
 <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css"> <link rel="stylesheet" type="text/css" href="https://npmcdn.com/flatpickr/dist/themes/dark.css"> <script src="https://npmcdn.com/flatpickr/dist/flatpickr.min.js"></script> <script src="https://npmcdn.com/flatpickr/dist/l10n/ru.js"></script> </head> <body> <div id="datepicker"> <input type="text" id="end-date-picker"> <input type="text" id="beg-date-picker"> </div> <span id="end-str-date"></span> <br> <span id="beg-str-date"></span> </body>

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

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