<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<div onclick="prevDay()">前一天</div>
<div id="daytimer"></div>
<div onclick="nextDay()">后一天</div>
</div>
</body>
</html>
<script>
var daytimer = document.getElementById('daytimer');
var currentDate = new Date();
var currentYear = currentDate.getFullYear();
var currentMonth = currentDate.getMonth() + 1;
var currentDay = currentDate.getDate();
var currentTimestamp = currentDate.getTime();
daytimer.innerHTML = currentYear + '-' + currentMonth + '-' + currentDay;
function prevDay() {
currentTimestamp -= 24 * 60 * 60 * 1000;
var prevDate = new Date(currentTimestamp);
var prevYear = prevDate.getFullYear();
var prevMonth = prevDate.getMonth() + 1;
var prevDay = prevDate.getDate();
daytimer.innerHTML = prevYear + '-' + prevMonth + '-' + prevDay;
}
function nextDay() {
currentTimestamp += 24 * 60 * 60 * 1000;
var nextDate = new Date(currentTimestamp);
var nextYear = nextDate.getFullYear();
var nextMonth = nextDate.getMonth() + 1;
var nextDay = nextDate.getDate();
daytimer.innerHTML = nextYear + '-' + nextMonth + '-' + nextDay;
}
</script>