格式化时间函数:
1 function dateFormat(date, format) {
2 if (typeof date === "string") {
3 var mts = date.match(/(\/Date\((\d+)\)\/)/);
4 if (mts && mts.length >= 3) {
5 date = parseInt(mts[2]);
6 }
7 }
8 date = new Date(date);
9 if (!date || date.toUTCString() == "Invalid Date") {
10 return "";
11 }
12 var map = {
13 "M": date.getMonth() + 1, //月份
14 "d": date.getDate(), //日
15 "h": date.getHours(), //小时
16 "m": date.getMinutes(), //分
17 "s": date.getSeconds(), //秒
18 "q": Math.floor((date.getMonth() + 3) / 3), //季度
19 "S": date.getMilliseconds() //毫秒
20 };
21 format = format.replace(/([yMdhmsqS])+/g, function(all, t) {
22 var v = map[t];
23 if (v !== undefined) {
24 if (all.length > 1) {
25 v = '0' + v;
26 v = v.substr(v.length - 2);
27 }
28 return v;
29 } else if (t === 'y') {
30 return (date.getFullYear() + '').substr(4 - all.length);
31 }
32 return all;
33 });
34 return format;
35 }
36 return dateFormat(value, arg);