js 獲取指定日期的前幾天日期或後幾天日期
阿新 • • 發佈:2019-01-26
引數說明:fromDate是"yyyy-MM-dd"的日期格式,為指定日期,例如‘2014-10-10’
dayInterval表示間隔天數,間隔天數大於0,則得到比指定日期大dayInterval天的日期,間隔天數小於0,則得到比指定日期小dayInterval天的日期
function getDateFromCurrentDate(fromDate,dayInterval){
var curDate = new Date(Date.parse(fromDate.replace(/-/g,"/")));curDate.setDate(curDate.getDate()+dayInterval);
var year = curDate.getFullYear();
var month = (curDate.getMonth()+1)<10?"0"+(curDate.getMonth()+1):(curDate.getMonth()+1);
var day = curDate.getDate()<10?"0"+curDate.getDate():curDate.getDate();
return year+"-"+month+"-"+day;
};