javaScript 日期
Date.prototype.format_cm_export_time = function () {
var s = "";
var mouth =
this.getMonth() + 1 >= 10
? this.getMonth() + 1
: "0" + (this.getMonth() + 1);
var day = this.getDate() >= 10 ? this.getDate() : "0" + this.getDate();
s += this.getFullYear() + "-";
s += mouth + "-";
s += day;
return s;
};
Date.prototype.pushDateDayT = function (num) {
if (num == undefined) num = -2;
return new Date(
this.getTime() + Number(num) * 24 * 60 * 60 * 1000
).format_cm_export_time();
};
Date.prototype.pushDateWeekT = function (num) {
if (num == undefined) num = -1;
var timesp = new Date(this.getTime() + num * 7 * 24 * 60 * 60 * 1000);
if (timesp.getDay() < 0) {
num = -timesp.getDay() - 6;
} else {
num = -timesp.getDay() + 1;
}
return new Date(
timesp.getTime() + num * 24 * 60 * 60 * 1000
).format_cm_export_time();
};
Date.prototype.getPreMontht = function () {
var s = "";
var year = this.getFullYear();
var month =
this.getMonth() + 1 >= 10
? this.getMonth() + 1
: "0" + (this.getMonth() + 1);
var day = this.getDate() >= 10 ? this.getDate() : "0" + this.getDate();
var num = day < 25 ? 2 : 1;
while (num != 0) {
num--;
month = parseInt(month) - 1;
if (month == 0) {
year = parseInt(year) - 1;
month = 12;
}
}
var day2 = new Date(year, month, 0);
day2 = day2.getDate();
if (day > day2) {
day = day2;
}
month = month >= 10 ? month : "0" + month;
s += year + "-";
s += month + "";
return s;
};
Date.prototype.pushDateMonthT = function (num) {
if (num == undefined) num = -1;
var numy = 0;
var time = this;
var a = time.getDate();
while (num != 0) {
if (num > 0) {
num--;
var c =
new Date(
time.format_cm_export_time().substring(0, 4),
time.format_cm_export_time().substring(5, 7),
0
).getDate() - time.getDate();
numy = numy + c + a;
} else {
num++;
numy = numy - time.getDate();
}
time = new Date(this.getTime() + numy * 24 * 60 * 60 * 1000);
}
var b = time.getDate();
if (a < b) {
time = new Date(time.getTime() + (a - b) * 24 * 60 * 60 * 1000);
}
return time.format_cm_export_time();
};
Date.prototype.beginBetweenEnd = function (begin, end) {
var db = new Date();
db.setUTCFullYear(
begin.substring(0, 4),
begin.substring(4, 6) - 1,
begin.substring(6, 8)
);
var de = new Date();
de.setUTCFullYear(
end.substring(0, 4),
end.substring(4, 6) - 1,
end.substring(6, 8)
);
var unixDb = db.getTime();
var unixDe = de.getTime();
var list = [];
for (var k = unixDb; k <= unixDe;) {
list.push(new Date(parseInt(k)).format_cm_export_time());
k = k + 24 * 60 * 60 * 1000;
}
return list;
};