1 function DateFormt(time, format) { 2 var testDate = new Date(time * 1000); 3 var o = 4 { 5 "M+": testDate.getMonth() + 1, 6 "d+": testDate.getDate(), 7 "h+": testDate.getHours(), 8 "m+": testDate.getMinutes(), 9 "s+": testDate.getSeconds(), 10 "q+": Math.floor((testDate.getMonth() + 3) / 3), 11 "S": testDate.getMilliseconds() 12 } 13 if (/(y+)/.test(format)) { 14 format = format.replace(RegExp.$1, (testDate.getFullYear() + "").substr(4 - RegExp.$1.length)); 15 } 16 for (var k in o) { 17 if (new RegExp("(" + k + ")").test(format)) { 18 format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); 19 } 20 } 21 return format; 22 }