<header>
<h2 class="title">Date.prototype.setUTCFullYear()</h2>
<p class="description">Метод setUTCFullYear() встановлює рік для зазначеної дати за всесвітнім координованим часом (UTC).</p>
</header>
<main>
<div class="result">
<label for="year">Рік: </label>
<input type="number" id="year" value="2022">
<button onclick="changeYear()">Змінити Рік</button>
<p id="output">Тут буде результат</p>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: 'Arial', sans-serif;
}
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 {
display: inline-block;
background-color: #4CAF50;
border: none;
color: white;
text-align: center;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
function changeYear() {
// Знаходимо елементи на сторінці
let yearInput = document.getElementById('year');
let output = document.getElementById('output');
// Створюємо новий об'єкт дати
let date = new Date();
// Встановлюємо рік з інпута
date.setUTCFullYear(yearInput.value);
// Виводимо змінену дату
output.textContent = 'Змінена дата: ' + date.toUTCString();
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.