代码: 复制代码 代码如下: <BR>var format = function(time, format){ <BR>var t = new Date(time); <BR>var tf = function(i){return (i < 10 ? '0' : '') + i}; <BR>return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){ <BR>switch(a){ <BR>case 'yyyy': <BR>return tf(t.getFullYear()); <BR>break; <BR>case 'MM': <BR>return tf(t.getMonth() + 1); <BR>break; <BR>case 'mm': <BR>return tf(t.getMinutes()); <BR>break; <BR>case 'dd': <BR>return tf(t.getDate()); <BR>break; <BR>case 'HH': <BR>return tf(t.getHours()); <BR>break; <BR>case 'ss': <BR>return tf(t.getSeconds()); <BR>break; <BR>}; <BR>}); <BR>}; <BR>alert(format(1396178344662, 'yyyy-MM-dd HH:mm:ss')); <BR>