<header>
<h2 class="title">Date.prototype.setTime()</h2>
<p class="description">Цей метод встановлює час об'єкта Date відповідно до кількості мілісекунд, переданих від 1 січня 1970 року UTC.</p>
</header>
<main>
<div class="result">
<button onclick="addHour()">Додати 1 годину</button>
<button onclick="subtractHour()">Відняти 1 годину</button>
<p id="dateDisplay"></p>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
button {
margin: 5px;
padding: 10px;
cursor: pointer;
}
// Створення нового об'єкта Date
let currentDate = new Date();
displayDate();
function addHour() {
// Додаємо 1 годину (1 * 60 * 60 * 1000 мілісекунд) за допомогою методу setTime
currentDate.setTime(currentDate.getTime() + 1 * 60 * 60 * 1000);
displayDate();
}
function subtractHour() {
// Віднімаємо 1 годину (1 * 60 * 60 * 1000 мілісекунд) за допомогою методу setTime
currentDate.setTime(currentDate.getTime() - 1 * 60 * 60 * 1000);
displayDate();
}
function displayDate() {
document.getElementById('dateDisplay').innerHTML = currentDate.toString();
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.