var day=0;
var month=0;
var year=0;
var today="";
mydate=new Date();
mymonth=mydate.getMonth()+1;
myday= mydate.getDate();
myyear= mydate.getFullYear();
year=(myyear > 200) ? myyear : 1900 + myyear;
if(mymonth >= 10){mymonth=mymonth;}else{mymonth="0" + mymonth;}
if(myday >= 10){myday=myday;}else{myday="0" + myday;}
today=year+'-'+mymonth+'-'+myday;//2017-09-05;
//去除<=10的月份、日期前的0;
if(mymonth <= 10){
mymonth = mymonth.replace('0','')
}else{
mymonth= mymonth;
}
if(myday <= 10){
myday = myday.replace('0','')
}else{
myday= myday;
}
//获取当前年月
var date=new Date;
var year=date.getFullYear();
var month=date.getMonth()+1;
month =(month<10 ? "0"+month:month);//加0
var mydate = (year.toString()+'-'+month.toString());
//获取当前日期
function getDay(day){
var today = new Date();
var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
today.setTime(targetday_milliseconds); //注意,这行是关键代码
var tYear = today.getFullYear();
var tMonth = today.getMonth();
var tDate = today.getDate();
tMonth = doHandleMonth(tMonth + 1);
tDate = doHandleMonth(tDate);
return tYear+"-"+tMonth+"-"+tDate;
}
//日期拼接
function doHandleMonth(month){
var m = month;
if(month.toString().length == 1){
m = "0" + month;
}
return m;
}
var Yesterday = getDay(-1),Today = getDay(0),Last3days = getDay(-2)+','+getDay(0),Last7days = getDay(-6)+','+getDay(0); //取值