See the Pen 2021년 크리스마스 계산기 by yoonbitnara (@yoonbitnara) on CodePen.



HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="wrap">
    <h1>D-day</h1>
    <div id="resArea"></div>
  </div>
</body>

</html>



CSS

div#wrap {
  width: 740px;
  padding: 10px;
  border: 1px solid #000;
  margin: 20px auto;
}
div#resArea {
  font-size: 30px;
}



JS

let xmas = new Date(2021, 11, 24);
let now = new Date();
xmas = xmas.getTime();
now = now.getTime();

let timeData = xmas - now;
let resDate = Math.floor(timeData / 24 / 60 / 60 / 1000);
document.getElementById("resArea").innerText =
  "크리스마스까지 " + resDate + "일 남음";

Leave a comment