<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=uft-8">
<script language="javascript">
Date.prototype.format = function (format)
{
var o = {
"M ": this.getMonth() 1, //month
"d ": this.getDate(), //day
"h ": this.getHours(), //hour
"m ": this.getMinutes(), //minute
"s ": this.getSeconds(), //second
"q ": Math.floor((this.getMonth() 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y )/.test(format)) format = format.replace(RegExp.$1,
(this.getFullYear() "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" k ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length == 1 ? o[k] :
("00" o[k]).substr(("" o[k]).length));
return format;
}
//页面调用
function onBigBlur() {
var bigCycle = document.getElementById("txt_dbigcycle");
var bignextTime = document.getElementById("txt_dnextbigtime");
var bigTime = document.getElementById("txt_dbigtime").value.replace('-', '/').replace('-', '/');
var d = new Date(bigTime);
var LSTR_Date = d.format("yyyyMMdd");
//(日期表示只有这一种格式,不支持民国年)
var LSTR_AddDays = parseInt(bigCycle.value);
var LSTR_DateType = "YYYYMMDD";
var result = AddDate(LSTR_Date, LSTR_AddDays, LSTR_DateType);
var LSTR_YY = parseInt(result.substr(0, 4), 10);
var LSTR_MM = parseInt(result.substr(4, 2), 10);
var LSTR_DD = parseInt(result.substr(6, 2), 10);
bignextTime.value= LSTR_YY "-" LSTR_MM "-" LSTR_DD;
}
function AddDate(LISTR_Date, LISTR_AddDays, LISTR_DateType) {
var LSTR_YY = 0;
var LSTR_MM = 0;
var LSTR_DD = 0;
var LINT_FLAG = 0;
//检查日期格式为 "YYYYMMDD" 或
//"MMDDYYYY" 且长度为8码
if ((LISTR_DateType != "YYYYMMDD") && (LISTR_DateType != "MMDDYYYY") && (LISTR_Date.length != 8))
return false;
if (LISTR_DateType == "MMDDYYYY")
LISTR_Date = LISTR_Date.substr(4, 4) LISTR_Date.substr(0, 4);
LSTR_YY = parseInt(LISTR_Date.substr(0, 4), 10);
LSTR_MM = parseInt(LISTR_Date.substr(4, 2), 10);
LSTR_DD = parseInt(LISTR_Date.substr(6, 2), 10) parseInt(LISTR_AddDays, 10);
while (LINT_FLAG == 0) {
switch (LSTR_MM) {
case 2:
if ((LSTR_YY % 4) != 0) {
if (LSTR_DD > 28) {
LSTR_DD -= 28;
LSTR_MM = 3;
}
else {
LINT_FLAG = 1;
}
}
else {
if (((LSTR_YY % 100) == 0) && ((LSTR_YY % 400) != 0)) {
if (LSTR_DD > 28) {
LSTR_DD -= 28;
LSTR_MM = 3;
}
else {
LINT_FLAG = 1;
}
}
else {
if (LSTR_DD > 29) {
LSTR_DD -= 29;
LSTR_MM = 3;
}
else {
LINT_FLAG = 1;
}
}
}
break;
case 4:
case 6:
case 9:
case 11:
if (LSTR_DD > 30) {
LSTR_DD -= 30;
LSTR_MM = 1;
}
else { LINT_FLAG = 1; }
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
if (LSTR_DD > 31) {
LSTR_DD -= 31;
LSTR_MM = 1;
}
else {
LINT_FLAG = 1;
}
break;
case 12:
if (LSTR_DD > 31) {
LSTR_DD -= 31;
LSTR_MM = 1;
LSTR_YY = 1;
}
else {
LINT_FLAG = 1;
}
break;
default:
return;
break;
}
}
if (LSTR_MM < 10) {
LSTR_MM = "0" LSTR_MM;
}
if (LSTR_DD < 10) {
LSTR_DD = "0" LSTR_DD;
}
if (LISTR_DateType == "MMDDYYYY")
return LSTR_MM "" LSTR_DD "" LSTR_YY "";
else
return LSTR_YY "" LSTR_MM "" LSTR_DD "";
}
</script>