【js封装】日期格式化

timeToDate(time, format){
            var t = new Date(time);
            var tf = function(i){return (i < 10 ? '0' : '') + i};
            return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
            switch(a){
            case 'yyyy':
            return tf(t.getFullYear());
            break;
            case 'MM':
            return tf(t.getMonth() + 1);
            break;
            case 'dd':
            return tf(t.getDate());
            break;
            case 'mm':
            return tf(t.getMinutes());
            break;
            case 'HH':
            return tf(t.getHours());
            break;
            case 'ss':
            return tf(t.getSeconds());
            break;
            };
            });
        },
使用:
timeToDate(params.row.start_time*1000,'yyyy-MM-dd HH:mm:ss')

 

posted @ 2020-04-23 12:39  expworld  阅读(157)  评论(0编辑  收藏  举报