js中转换日期格式

来源:互联网 发布:win7网络图标不见了 编辑:程序博客网 时间:2024/04/28 04:48
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;        }    })}alert(format("Thu Aug 22 2013 15:12:00 GMT+0800", 'yyyy-MM-dd HH:mm:ss'))

0 0
原创粉丝点击