var locale = {
"format": 'YYYY/MM/DD',
"separator": " - ",
"applyLabel": "確定",
"cancelLabel": "取消",
"fromLabel": "起始時間",
"toLabel": "結束時間'",
"customRangeLabel": "自定義",
"weekLabel": "W",
"daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"],
"monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
"firstDay": 1
};
注意:format 格式化日期格式時必須大寫,遇到過小寫獲取不到日期的情況。
$('#stedDate').daterangepicker(
{
"minDate":moment().subtract(90,'days'),
"maxDate":moment().add(90,'days'),
//"singleDatePicker": true,
"autoApply": true,
"startDate": "moment()",
"endDate": "moment()",
"locale": locale,
}
);
還有一種選擇日期范圍的
$('#scopeDate').daterangepicker(
{
"ranges": {
'今天': [moment(), moment()],
'一周內': [moment().subtract(6, 'days'), moment()],
'一個月內': [moment().subtract(1, 'month').startOf('month'), moment().subtract('month')],
'兩個月內': [moment().subtract(2, 'month').startOf('month'), moment().subtract('month')],
'三個月內': [moment().subtract(3, 'month').startOf('month'), moment().subtract('month')]
},
"showCustomRangeLabel": false,
"locale": locale,
});
此方法如果想讓input內顯示“今天”,“一周內”,“一個月內”等等文字的話可以在寫一個input 定位覆蓋在上方給,把獲取到的值傳去
$('.ranges ul li').click(function () {
$('#scopeDates').val($(this).html())
});