system-time

by tianyk

HTML

<p id="system-time">

</p>

CSS

html,
body {
  height: 100%;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

#system-time {
  color: #212121;
  font-family: arial, sans-serif;
  font-size: xx-large;

  text-align: center;
}

JavaScript

const systemTimeEl = document.getElementById('system-time');



setInterval(() => {
  const now = new Date();
  const year = now.getFullYear();
  const month = ('' + (now.getMonth() + 1)).padStart(2, '0');
  const date = ('' + now.getDate()).padStart(2, '0');
  const hour = ('' + now.getHours()).padStart(2, '0');
  const minute = ('' + now.getMinutes()).padStart(2, '0');
  const secound = ('' + now.getSeconds()).padStart(2, '0');

  systemTimeEl.textContent = `${year}-${month}-${date} ${hour}:${minute}:${secound}`;
}, 1000);