I have tried coding a JS world clock. The world clock itself is posted on stackoverflow.com but I do not know how to get output values from "forEach" into html properly. Would anyone tell me the correct coding or reference sites? Thank you.
Ref. How to get list of all timezones in javascript How to get list of all timezones in javascript
JS code below works but it is just my guesswork.(JS beginner)
setInterval(() => {
let out = "";
const city = ['Asia/Taipei', 'America/New_York'];
city.forEach(adjustTime);
function adjustTime(item) {
const today = new Date();
const localTime = today.toLocaleString("ja-JP", {
timeZone: `${item}`
});
out += item + localTime + "<br>";
document.getElementById("output").innerHTML = out;
}
}, 1000);
<p id="output"></p>
\`` – mplungjan Jun 13 '22 at 08:01
";' to get html output, but I do not know if the coding correct. Thank you for commenting. – takekawa Jun 13 '22 at 08:05