js 获取当前日期或者前、后N天yyyy-MM-dd的方法

//js获取当前日期、当前日期前、后N天的标准年月日

//day=0为当前天,day=7为前7天,day=-7为当前日期的后7天

function getstartdate(day) {
            var beginDate;
            var curr_time = new Date();
            var week_time = new Date(curr_time.getTime() - 1000 * 60 * 60 * 24 * day);
            var curyear = week_time.getFullYear();
            var curmonth = week_time.getMonth() + 1;
            curmonth = curmonth > 9 ? curmonth.toString() : '0' + curmonth.toString();
            var curday = week_time.getDate();
            curday = curday > 9 ? curday.toString() : '0' + curday.toString();
            beginDate = curyear + "-" + curmonth + "-" + curday;
            return beginDate
        }

posted @ 2015-11-09 18:26  沙漠绿洲uibe  阅读(665)  评论(0编辑  收藏  举报