function formatDate(date){
let year = date.getFullYear();
let month = date.getMonth()+1;
let day = date.getDate();
month = month < 10 ?'0'+ month : month;
day = day < 10 ?'0'+ day : day; return year +'-'+ month +'-'+ day;
}console.log(formatDate(new Date()));
//加7天 var d = new Date(); d.setDate(d.getDate() + 7); $("#txtEndTime").val(formatDate(d));
//加一年 var d = new Date(); d.setFullYear(d.getFullYear()+1);
$("#txtEndTime").val(formatDate(d));