怎么把js获取的系统时间加一年
发布网友
发布时间:2022-04-20 14:56
我来回答
共2个回答
热心网友
时间:2023-07-12 22:01
将年+1即可,代码如下:
var now = new Date();
now.setFullYear(now.getFullYear()+1);
alert(now);
热心网友
时间:2023-07-12 22:01
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script>
function f1(){
var d = new Date();
var year = d.getFullYear()+1;
var month = d.getMonth();
var day = d.getDate();
var hour = d.getHours();
var minute = d.getMinutes();
var second = d.getSeconds();
var dateStr = '明天的今天是:'
+ year + "年"
+ (month + 1) + "月"
+ day + "日"
+ hour + "时"
+ minute + "分"
+ second + "秒";
document.getElementById('d1').innerHTML = dateStr;
}
</script>
</head>
<body>
<input type="button" value="时间显示" onclick="f1();"/>
<div id="d1"></div>
</body>
</html>