Commit 16feb579a74169f8920b489680ec9d16dd24dda6
1 parent
4b42ccae
提交
Showing
1 changed file
with
50 additions
and
0 deletions
src/main/webapp/static/js/date.js
0 → 100644
1 | +/** | ||
2 | + * | ||
3 | + */ | ||
4 | +function parseToDate(value) { | ||
5 | + if (value == null || value == '') { | ||
6 | + return undefined; | ||
7 | + } | ||
8 | + var dt; | ||
9 | + if (value instanceof Date) { | ||
10 | + dt = value; | ||
11 | + } | ||
12 | + else { | ||
13 | + if (!isNaN(value)) { | ||
14 | + dt = new Date(value); | ||
15 | + } | ||
16 | + else if (value.indexOf('/Date') > -1) { | ||
17 | + value = value.replace(/\/Date(−?\d+)\//, '$1'); | ||
18 | + dt = new Date(); | ||
19 | + dt.setTime(value); | ||
20 | + } else if (value.indexOf('/') > -1) { | ||
21 | + dt = new Date(Date.parse(value.replace(/-/g, '/'))); | ||
22 | + } else { | ||
23 | + dt = new Date(value); | ||
24 | + } | ||
25 | + } | ||
26 | + return dt; | ||
27 | +} | ||
28 | + | ||
29 | +//为Date类型拓展一个format方法,用于格式化日期 | ||
30 | +Date.prototype.format = function (format) //author: meizz | ||
31 | +{ | ||
32 | + var o = { | ||
33 | + "M+": this.getMonth() + 1, //month | ||
34 | + "d+": this.getDate(), //day | ||
35 | + "h+": this.getHours(), //hour | ||
36 | + "m+": this.getMinutes(), //minute | ||
37 | + "s+": this.getSeconds(), //second | ||
38 | + "q+": Math.floor((this.getMonth() + 3) / 3), //quarter | ||
39 | + "S": this.getMilliseconds() //millisecond | ||
40 | + }; | ||
41 | + if (/(y+)/.test(format)) | ||
42 | + format = format.replace(RegExp.$1, | ||
43 | + (this.getFullYear() + "").substr(4 - RegExp.$1.length)); | ||
44 | + for (var k in o) | ||
45 | + if (new RegExp("(" + k + ")").test(format)) | ||
46 | + format = format.replace(RegExp.$1, | ||
47 | + RegExp.$1.length == 1 ? o[k] : | ||
48 | + ("00" + o[k]).substr(("" + o[k]).length)); | ||
49 | + return format; | ||
50 | +}; |