倒推天数的算法

//times 为 number
    timer: function(times) {
        var today = new Date();
        var Days = new Date();
        Days.setDate(today.getDate() - times);
        Years = Days.getFullYear();
        Months = (Days.getMonth() + 1) > 9 ? (Days.getMonth() + 1) : "0"+(Days.getMonth() + 1);
        Dayer = Days.getDate() > 9 ? Days.getDate() : "0"+Days.getDate();
        return  parseInt(Years + "" + Months + "" + Dayer);
    }
//输出的格式为 : YYYYMMDD

 

posted on 2018-08-06 16:02  HMirror  阅读(536)  评论(0编辑  收藏  举报