1,属性设置
$(function () {
//Date range picker with time picker
$('#reservationtime-1').daterangepicker({
timePicker: false,
timePickerIncrement: 1,
timePicker24Hour: true,
autoApply: true,
singleDatePicker: true,
locale: {
format: 'YYYY-MM-DD',
daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
applyLabel: '确定',
cancelLabel: '返回',
separator: ' - '
}
});
//Date range picker with time picker
$('#reservationtime-2').daterangepicker({
timePicker: false,
timePickerIncrement: 1,
timePicker24Hour: true,
autoApply: true,
singleDatePicker: true,
locale: {
format: 'YYYY-MM-DD',
daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
applyLabel: '确定',
cancelLabel: '返回',
separator: ' - '
}
});
});
2,设置日期为7天前
function GetDate()
{
var date = new Date();
year = date.getFullYear().toString().padStart(4, '0');
month = (date.getMonth() + 1).toString().padStart(2, '0');
day = date.getDate().toString().padStart(2, '0');
return year + '-' + month +'-' + day;
}
function GetSumDate(index) {
var date = new Date(); //当前日期
var newDate = new Date();
newDate.setDate(date.getDate() + index);//官方文档上虽然说setDate参数是1-31,其实是可以设置负数的
var time = newDate.getFullYear().toString().padStart(4, '0')+"-"+((newDate.getMonth() + 1).toString().padStart(2, '0'))+"-"+newDate.getDate().toString().padStart(2, '0');
return time;
}
function SearchSeven()
{
//一定要用ID,用name改不了
document.getElementById("reservationtime-1").value = GetSumDate(-7);
document.getElementById("reservationtime-2").value = GetDate();
}