JQ:
$(function(){
//设置几天前的时间
var startDate = new Date();
//这里设置是十天前,则减去相应的毫秒数。
startDate.setTime(startDate.getTime()-10*24*60*60*1000);
var seperator = "-";
var year = startDate.getFullYear();
var month = startDate.getMonth() + 1;
var strDate = startDate.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
//生成十天前的时间格式。
var sDate = year + seperator + month + seperator + strDate;
//设置几天后的天数
var endDate = new Date();
//这里设置是十天前,则加起相应的毫秒数。
endDate.setTime(endDate.getTime()+10*24*60*60*1000);
year = endDate.getFullYear();
month = endDate.getMonth() + 1;
strDate = endDate.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var eDate = year + seperator + month + seperator + strDate;
//设置关联容器的val
$("#start-time").val(sDate);
$("#end-time").val(eDate);
});