//格式化時間orm
var formatDate = function(time, format){get
var t = new Date(time);it
var tf = function(i){return (i < 10 ? '0' : '') + i};io
return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){console
switch(a){function
case 'yyyy':form
return tf(t.getFullYear());im
break;時間
case 'MM':co
return tf(t.getMonth() + 1);
break;
case 'mm':
return tf(t.getMinutes());
break;
case 'dd':
return tf(t.getDate());
break;
case 'HH':
return tf(t.getHours());
break;
case 'ss':
return tf(t.getSeconds());
break;
}
})
}
console.log(formatDate(new Date().getTime(), 'yyyy-MM-dd HH:mm:ss'))