LoginSignup
0
0

世界の時間を表示する

Posted at

世界中の時間を表示します。
worldsDataに場所と日本からの時差を入れます。

<div id="world-time"></div>
const worldsData = [
  {
    location: "東京",
    TimeDifference: 0
  },
  {
    location: "ベルリン",
    TimeDifference: -8
  },
  {
    location: "上海",
    TimeDifference: -1
  },
  {
    location: "ニューヨーク",
    TimeDifference: -14
  },
  {
    location: "ロサンゼルス",
    TimeDifference: -16
  },
]
const content = document.getElementById('world-time');

worldsData.forEach(function (world) {
  const now = new Date(new Date().getTime() + world.TimeDifference * 60 * 60 * 1000);
  const year = now.getFullYear();
  const month = now.getMonth() + 1;
  const day = now.getDate();
  const hour = now.getHours();
  const minu = now.getMinutes();
  
  const divElement2 = document.createElement('div');

  divElement2.innerHTML = `
  <ul>
    <li>${world.location}</li>
    <li>${`${year}${month}${day}${hour}:${minu}`}</li>
  </ul>
  <br><br>
  `
  content.appendChild(divElement2)
});

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0