<!doctype html>
<html>
<head>
<title>标题</title>
<meta charset="utf-8">
<script>
var now=new Date();
//复制日期对象,用于计算
var end=new Date(now);
//计算最晚能买到哪天的火车票
/*
//Step1:取出今天的日期
var d=now.getDate();
//Step2:做加减
d+=60;
//Step3:放回去
now.setDate(d);
*/
end.setDate(end.getDate()+60);
//console.log(now);
//console.log(end);
/*
//定义入职时间hiredate:2012/6/30
var hiredate=
new Date("2012/6/30");
//复制hiredate到到期时间enddate
var enddate=new Date(hiredate);
//将enddate+3年
enddate.setFullYear(
enddate.getFullYear()+3
);
//复制enddate到续签时间renewdate
var renewdate=new Date(enddate);
//将renewdate-1月
renewdate.setMonth(
renewdate.getMonth()-1
);
//如果renewdate是周六
if(renewdate.getDay()==6){
//就renewdate-1天
renewdate.setDate(
renewdate.getDate()-1
);
}else if(renewdate.getDay()==0){
//否则,如果是周日,
//就renewdate-2天
renewdate.setDate(
renewdate.getDate()-2
);
}
//将renewdate复制到提醒时间alertdate
var alertdate=
new Date(renewdate);
//将alertdate-7天
alertdate.setDate(
alertdate.getDate()-7
);
console.log(
hiredate,enddate,renewdate,alertdate
);
*/
function workDays(days){
//获得当前时间now
var now=new Date();
//i从1,到<=days+1
for(var i=1;i<=days+1;i++){
//now+
now.setDate(now.getDate()+
//如果now是周五,就+3天
(now.getDay()==5?3:
//否则,如果now是周六,就+2天
now.getDay()==6?2:
//否则,就+1天
1)
);
}//(循环结束)输出now
console.log(now);
}
workDays(10);
</script>
</head>
<body>
</body>
</html>
javascriptAPI(Date)(二)
最新推荐文章于 2024-04-30 09:20:26 发布