<header>
  <h2 class="title">Date.prototype.getUTCMilliseconds()</h2>
  <p class="description">Повертає мілісекунди поточного об'єкта Date у форматі UTC.</p>
</header>
<main>
  <div class="result">
    <div id="clock">XX:XX:XX.XXX</div>
    <button onclick="toggleClock()">Старт/Стоп</button>
  </div>
</main>
body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-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;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

#clock {
  font-size: 2em;
  margin-bottom: 20px;
}

button {
  cursor: pointer;
  background-color: #4CAF50;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
}

button:hover {
  background-color: #45a049;
}
let clockInterval;
let running = false;

function toggleClock() {
  if (running) {
    clearInterval(clockInterval);
  } else {
    updateClock();
    clockInterval = setInterval(updateClock, 1);
  }
  running = !running;
}

function updateClock() {
  const now = new Date();
  const hours = String(now.getUTCHours()).padStart(2, '0');
  const minutes = String(now.getUTCMinutes()).padStart(2, '0');
  const seconds = String(now.getUTCSeconds()).padStart(2, '0');
  const milliseconds = String(now.getUTCMilliseconds()).padStart(3, '0');
  
  document.getElementById('clock').textContent = `${hours}:${minutes}:${seconds}.${milliseconds}`;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.