当我从上午/下午更改为24时钟时,小时选择器只允许提前23小时。这是日期范围选择器或moment.js转换问题的常见错误吗?
我会上传我的照片以防万一.js需要时间从我的服务器?并且不能超过23小时......
另请使用我的代码查看codepen。
"setStartDate": [moment().startOf('day')],
"setEndDate": [moment()]
答案 0 :(得分:1)
注意format
选项,您必须使用有效的时刻代币,MM
代表月份,而小写mm
代表分钟,SS
代表小数秒,对于secods使用小写ss
,请参阅时刻docs以供进一步参考。
此外startDate
和endDate
options接受日期对象,时刻对象或字符串,您传递数组,这就是您获得无效日期的原因
这是一个实时代码段:
$('#demo').daterangepicker({
"timePicker": true,
"timePicker24Hour": true,
"autoApply": true,
"locale": {
"format": "DD/MM/YYYY HH:mm:ss",
"separator": " - ",
"applyLabel": "Apply",
"cancelLabel": "Cancel",
"fromLabel": "From",
"toLabel": "To",
"customRangeLabel": "Custom",
"weekLabel": "W",
"daysOfWeek": [
"Su",
"Mo",
"Tu",
"We",
"Th",
"Fr",
"Sa"
],
"monthNames": [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
],
"firstDay": 1
},
"startDate": moment().startOf('day'),
"endDate": moment()
}, function(start, end, label) {
console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/bootstrap/3/css/bootstrap.css" />
<!-- Include Date Range Picker -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
<input type="text" id="demo" style="width: 300px;"></input>