js 获取最近几天的时间字符串
function GetDateStr(AddDayCount) {
var dd = new Date();
dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
var y = dd.getFullYear();
var m = dd.getMonth()+1;//获取当前月份的日期
var d = dd.getDate();
//判断 月
if(m < 10){
m = "0" + m;
}else{
m = m;
}
//判断 日n
if(d < 10){//如果天数<10
d = "0" + d;
}else{
d = d;
}
return y+"-"+m+"-"+d;
}
var time = GetDateStr(-2);
alert(time);