使用来自http://www.daterangepicker.com/#examples的配置生成器,我选择了“范围(带有示例预定义范围)”并得到以下 JS:
$('#demo').daterangepicker({
"ranges": {
"Today": [
"2016-10-17T04:27:01.501Z",
"2016-10-17T04:27:01.501Z"
],
"Yesterday": [
"2016-10-16T04:27:01.501Z",
"2016-10-16T04:27:01.501Z"
],
"Last 7 Days": [
"2016-10-11T04:27:01.501Z",
"2016-10-17T04:27:01.501Z"
],
"Last 30 Days": [
"2016-09-18T04:27:01.501Z",
"2016-10-17T04:27:01.501Z"
],
"This Month": [
"2016-10-01T05:00:00.000Z",
"2016-11-01T04:59:59.999Z"
],
"Last Month": [
"2016-09-01T05:00:00.000Z",
"2016-10-01T04:59:59.999Z"
]
},
"startDate": "10/10/2016",
"endDate": "10/16/2016"
}, function(start, end, label) {
console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});
不幸的是,当我使用它时,每个日期都是无效的。这是一个展示我的意思的 JS 小提琴:
https://jsfiddle.net/LgetLa6c/
如果您将鼠标悬停在任何内容上,它会显示“日期无效”。唯一没有说“无效日期”的是“自定义范围”。