代: 复制代 代码如下: <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.getFull Year()); <BR>case 'MM': <BR>return tf(t.getMonth() 1); <BR>case 'mm': <BR> return tf(t.getMinutes()); <BR>break; <BR>case 'dd': <BR>return tf(t.getDate()); <BR>case 'HH': 🎜>return tf(t.getHours()); <BR>case 'ss': <BR>return tf(t.getSeconds()); <BR> >}); <BR>}; <BR>alert(format(1396178344662, 'yyyy-MM-dd HH:mm:ss')); <BR>