JavaScript-合同到期续约案例

时间:2021-11-02 06:13:30
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
//创建日期对象入职时间hiredate:2012/6/30;
var hiredate=new Date("2012/06/30");
//复制hiredate到enddate(到期时间)中
var enddate=new Date(hiredate); enddate.setFullYear( //将enddate+3年
enddate.getFullYear()+3
);
//复制到enddate到续签时间renewdate(提醒时间)
var renewdate=new Date(enddate);
//将renewdate-1月
renewdate.setMonth(
renewdate.getMonth()-1
); if(renewdate==6){//如果renewdate是周六
//renewdate-1天
renewdate.setDate(
renewdate.getMonth()-1
);
}else if(renewdate==0){//否则,如果renewdate是周日
renewdate.setDate(
renewdate.getDate()-2
);
//renewdate-2天
}
var alertdate=new Date(renewdate);
//复制renewdate到alertdate
alertdate.setDate(
alertdate.getDate()-7
);
//将alertdate-7天 console.log(
"到期时间:"+enddate+"\n",
"续签时间:"+renewdate+"\n",
"提醒时间:"+alertdate
);
</script>
</body>
</html>