美文网首页
Date转字符串

Date转字符串

作者: Aluha_f289 | 来源:发表于2019-08-14 21:36 被阅读0次
      //时间格式化
        var format = function(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 'mm':
                        return tf(t.getMinutes());
                        break;
                    case 'dd':
                        return tf(t.getDate());
                        break;
                    case 'HH':
                        return tf(t.getHours());
                        break;
                    case 'ss':
                        return tf(t.getSeconds());
                        break;
                }
            })
        }

相关文章

网友评论

      本文标题:Date转字符串

      本文链接:https://www.haomeiwen.com/subject/recojctx.html