//日期处理
Date.prototype.format = function (A) {
var B = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"H+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/.test(A)) {
A = A.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var C in B) {
if (new RegExp("(" + C + ")").test(A)) {
A = A.replace(RegExp.$1, RegExp.$1.length == 1 ? B[C] : ("00" + B[C]).substr(("" + B[C]).length));
}
}
return A;
};
}
Date.prototype.dateDiff = function (C, D) {
var B = 1;
if (!C) {
return "必须是日期对象";
}
var A = this.getTime() - C.getTime();
switch (D) {
case "ms":
B = 1;
break;
case "s":
B = 1000;
break;
case "m":
B = 60 * 1000;
break;
case "h":
B = 60 * 60 * 1000;
break;
case "d":
B = 24 * 60 * 60 * 1000;
break
}
return Math.floor(A / B);
};
Date.prototype.DateAdd = function (C, A) {
var B = this;
switch (C) {
case "s":
return new Date(Date.parse(B) + (1000 * A));
case "m":
return new Date(Date.parse(B) + (60000 * A));
case "h":
return new Date(Date.parse(B) + (3600000 * A));
case "d":
return new Date(Date.parse(B) + (86400000 * A));
case "w":
return new Date(Date.parse(B) + ((86400000 * 7) * A));
case "q":
return new Date(B.getFullYear(), (B.getMonth()) + A * 3, B.getDate(), B.getHours(), B.getMinutes(), B.getSeconds());
case "M":
return new Date(B.getFullYear(), (B.getMonth()) + A, B.getDate(), B.getHours(), B.getMinutes(), B.getSeconds());
case "y":
return new Date((B.getFullYear() + A), B.getMonth(), B.getDate(), B.getHours(), B.getMinutes(), B.getSeconds());
}
return B;
};
Date.prototype.Init = function (A) {
return new Date(A.replace(/-/g, "/"));
};
Date.StrToDate = function (A) {
return new Date(A.replace(/-/g, "/"));
};
Date.FormatTime = function (A) {
var H = "";
A = Math.round(A);
var B = A % 60;
if (B > 0) {
H = B + "秒";
A -= B;
}
if (A >= 60) {
var J = A / 60;
var E = J % 60;
J -= E;
H = E + "分" + H;
if (J >= 60) {
var I = J / 60;
var C = I % 24;
I -= C;
H = C + "时" + H;
if (I >= 24) {
var L = I / 24;
var G = L % 30;
H = G + "天" + H;
L -= G;
if (L >= 30) {
var F = L / 30;
var D = F % 12;
H = D + "月" + H;
F -= D;
if (F >= 12) {
var K = F / 12;
H = K + "年" + H;
}
}
}
}
}
return H;
};
function StrToDate(A) {
return new Date(A.replace(/-/g, "/"));
}