1 var formatDate = function(time, format){ 2 var t = new Date(time); 3 var tf = function(i){ return (i < 10 ? '0' : '') + i}; 4 return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){ 5 switch(a){ 6 case 'yyyy': 7 return tf(t.getFullYear()); 8 break; 9 case 'MM':10 return tf(t.getMonth() + 1);11 break;12 case 'mm':13 return tf(t.getMinutes());14 break;15 case 'dd':16 return tf(t.getDate());17 break;18 case 'HH':19 return tf(t.getHours());20 break;21 case 'ss':22 return tf(t.getSeconds());23 break;24 }25 })26 }
一直在用,总是忘记记录...以后再有的话继续修改.不然每次都要写,麻烦.
ZhLingF W