原生JavaScript另一种正则日期格式化函数及调用方法:
1 Date.prototype.format = function(format){ //author: meizz
2 var o = {
3 "M+" : this.getMonth()+1, //month
4 "d+" : this.getDate(), //day
5 "h+" : this.getHours(), //hour
6 "m+" : this.getMinutes(), //minute
7 "s+" : this.getSeconds(), //second
8 "q+" : Math.floor((this.getMonth()+3)/3), //quarter
9 "S" : this.getMilliseconds() //millisecond
10 }
11 if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
12 (this.getFullYear()+"").substr(4 - RegExp.$1.length));
13 for(var k in o)if(new RegExp("("+ k +")").test(format))
14 format = format.replace(RegExp.$1,
15 RegExp.$1.length==1 ? o[k] :
16 ("00"+ o[k]).substr((""+ o[k]).length));
17 return format;
18 }
19 alert(new Date().format("yyyy-MM-dd hh:mm:ss"));