js 日期格式化
function format(d, pattern){ var o = { "m+" : d.getMonth()+1, //month "d+" : d.getDate(), //day "H+" : d.getHours(), //hour "i+" : d.getMinutes(), //minute "s+" : d.getSeconds(), //second "S" : d.getMilliseconds() //millisecond } if(/(y+)/.test(pattern)) { pattern = pattern.replace(RegExp.$1, (d.getFullYear()+"").substr(4 - RegExp.$1.length)); } for(var k in o) { if(new RegExp("("+ k +")").test(pattern)) { pattern = pattern.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); } } return pattern; }
format(new Date(),'yyyy-mm-dd HH:ii:ss');