封装的时间函数怎么实现倒计时的功能.....

请问我这个封装的时间函数怎么实现倒计时的功能?

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>时间戳转化函数</title>
</head>

<body>
</body>
<script type="text/javascript">
    //日期格式化年月日时分秒函数
    var formatTimeToDate = function (time) {
        return new Date(time).format("yyyy-MM-dd hh:mm:ss");
    };
    //日期格式化年月日时
    var formatTimeToDay = function (time) {
        return new Date(time).format("yyyy-MM-dd");
    };
    Date.prototype.format = function (format) {
        var date = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S+": this.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1
                    ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
    };

    console.log(formatTimeToDate(1532156400000)) 
    console.log(formatTimeToDay(1532156400000))
</script>

</html>

JS有setInterval方法,就是用来做计时器的

var time = 5;//计时器计时次数,随便写了个5
var timer = setInterval(function(){
time --;
if(time > 0){
//这里写你要执行的方法
}else{
clearInterval(timer);
}
},1000)

我这是一秒一计时,倒计时5秒的方法