程式碼: 複製程式碼 程式碼如下: <BR>var format = 函數(時間, 格式){ <BR>var t = new Date(時間); <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>case 'mm': <BR> return tf( t.getMinutes()); <BR>break; case 'dd': <BR>return tf(t.getDate()); <BR>case 'HH': <BR>return tf(t.getHours()) ; <BR>case 'ss': <BR>return tf(t.getSeconds()); <BR>}; >}); <BR>}; <BR>alert(format(1396178344662, '🎜>alert(format(1396178344662, '-MM-yyyy dd HH:mm:ss')); <BR></腳本> <BR><BR>