var date_getPointDate = function (currDate, num) { ?//num表示天数,接受正负数 ?num = Math.floor(num); ?var symbol = ‘/‘; ?if(currDate.indexOf(‘-‘)>-1){ ???symbol = ‘-‘; ?}else if(currDate.indexOf(‘.‘) > -1){ ???symbol = ‘.‘; ?} ?var myDate = new Date(currDate); ?var lw = new Date(Number(myDate) + 1000 * 60 * 60 * 24 * num); //num天数 ?var lastY = lw.getFullYear(); ?var lastM = lw.getMonth()+1; ?var lastD = lw.getDate(); ?var startdate=lastY+ symbol +(lastM<10 ? "0" + lastM : lastM)+ symbol +(lastD<10 ? "0"+ lastD : lastD); ?return startdate;}console.log(date_getPointDate("2017-10-24", 30)) ?//2017-11-23console.log(date_getPointDate("2017/10/24", -30)) //2017/09/24// 调用规则 :// 指定日期n天前日期:date_getPointDate("2017/11/26", -30) //返回"2017/10/27"// 指定日期n天后日期:date_getPointDate("2017/10/27", 30) //返回"2017/11/26"
js获取指定日期之前/之后的某天——tool
原文地址:http://www.cnblogs.com/lonhon/p/7744101.html