<header>
<h2 class="title">Date.prototype.toTimeString()</h2>
<p class="description">Цей метод повертає часову частину дати в рядковому форматі.</p>
</header>
<main>
<div class="result">
<button id="getTimeBtn">Отримати час</button>
<p id="timeOutput">Тут буде виведено час.</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 {
background-color: #4caf50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: auto;
}
button:hover {
background-color: #45a049;
}
document.getElementById('getTimeBtn').addEventListener('click', function() {
// Створюємо новий об'єкт дати
let currentDate = new Date();
// Використовуємо toTimeString() для отримання часової частини дати
let timeString = currentDate.toTimeString();
// Виводимо часову частину в параграф з id="timeOutput"
document.getElementById('timeOutput').textContent = timeString;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.