指定日期 加减n天 返回日期

<html>
<script type="text/javascript">
function getNextDay(d){
        d = new Date(d);
        d = +d + 1000*60*60*24*2;
        d = new Date(d);
        //return d;
        //格式化
        var day=0;
        var month=0;
        if((d.getMonth()+1)<10){
        month="0"+(d.getMonth()+1);
        }else{
        month=d.getMonth()+1;
        }
        if(d.getDate()<10){
        day="0"+(d.getDate());
        }else{
        day=d.getDate();
        }
        alert(d.getFullYear()+"-"+month+"-"+day);
        return d.getFullYear()+"-"+month+"-"+day;
        
    }
</script>

<body>
<input type="button" onclick="getNextDay('2014-10-31')"/>
</body>
</html>

你可能感兴趣的:(JavaScript,js,前端,返回日期,指定日期,加减n天)