// 日期 加减 2015-01-01 +1 -1 返回 yyyy-mm-dd
function addNDays(newdate,daysToAdd){
var newtimems = newdate.getTime() + (daysToAdd 24 60 60 1000);
newdate.setTime(newtimems);
return formatDate(newdate);
}
//获取当月最后一天日期
function getFirstAndLastMonthDay( year, month){
var firstdate = year + '-' + month + '-01';
var day = new Date(year,month,0);
var lastdate = year + '-' + month + '-' + day.getDate();//获取当月最后一天日期
return lastdate;
}
//获取当月最后一天日期
function getLastMonthDay( year, month){
var firstdate = year + '-' + month + '-01';
var day = new Date(year,month,0);
var lastdate = day.getDate();//获取当月最后一天日期
return lastdate;
}
// 日期加一个月 2015-01 + 1
function addMonth(newdate, daysToAdd) {
var newtimems = newdate.getTime() + (daysToAdd 1 24 60 60 * 1000);
newdate.setTime(newtimems);
var c = formatMonth(newdate);
return c;
}
// 日期减一个月 2015-01 - 1
function subMonth(newdate,daysToAdd) {
var y =newdate.getFullYear();
var m =newdate.getMonth()+1;
var lastdate = getFirstAndLastMonthDay(y,m);//2015-01-01
var date=getLastMonthDay(y,m);
var lastd = lastdate.split('-');
var newtimems=new Date(lastd[0],parseInt(lastd[1])-1,lastd[2]).getTime()+(daysToAdddate246060*1000);
newdate.setTime(newtimems);
var c =formatMonth(newdate);
return c;
}
// 日期格式话 yyyy-mm
function formatMonth (date) {
var m =date.getMonth()+1;
if(m<10){
m="0"+m;
}
return date.getFullYear()+"-"+m;
}
// 日期格式话 yyyy-mm-dd
function formatDate(date) {
var m =date.getMonth()+1;
var d = date.getDate();
if(m<10){
m="0"+m;
}
if(d<10){
d="0"+d;
}
return date.getFullYear()+"-"+m+"-"+d;
}