js对日期增减天数的函数

    function addDays(date, num) {
        var targetday_milliseconds = date.getTime() + 1000 * 60 * 60 * 24 * num;
 
        date.setTime(targetday_milliseconds);  
 
        var tYear = date.getFullYear();
        var tMonth = date.getMonth();
        var tDate = date.getDate();
        tMonth = doHandleMonth(tMonth + 1);
        tDate = doHandleMonth(tDate);
        tHour = date.getHours();
        tMinute = date.getMinutes();
        tSecond = date.getSeconds();
        tHour = doHandleMonth(date.getHours());
        tMinute = doHandleMonth(date.getMinutes());
        tSecond = doHandleMonth(date.getSeconds());
 
        return tYear + "/" + tMonth + "/" + tDate + " " + tHour + ":" + tMinute + ":" + tSecond;
    }
 
    doHandleMonth : function(month){ 
        var m = month; 
        if(month.toString().length == 1){ 
            m = "0" + month; 
        } 
        return m; 
    }
posted @ 2012-10-14 23:20  永动机  阅读(2497)  评论(0编辑  收藏  举报