Due to the time difference around the world, we may encounter the following problems when chatting with foreigners: We just got up, and they are already preparing to go to bed. So I wrote a short piece of code as a simple time difference reference model.
<title>不同国家时间对照</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
</style>
<body>
<h1>不同国家时间对照</h1>
<table id="timeTable">
<thead>
<tr>
<th>国家</th>
<th>时间</th>
</tr>
</thead>
<tbody>
<tr>
<td>中国</td>
<td id="chinaTime"></td>
</tr>
<tr>
<td>美国</td>
<td id="usaTime"></td>
</tr>
<tr>
<td>日本</td>
<td id="japanTime"></td>
</tr>
<tr>
<td>澳大利亚</td>
<td id="australiaTime"></td>
</tr>
<tr>
<td>英国</td>
<td id="ukTime"></td>
</tr>
</tbody>
</table>
<script>
function updateTime() {
const now = new Date();
const chinaTime = new Date(now.getTime() + 8 * 3600 * 1000); // UTC+8
const usaTime = new Date(now.getTime() - 5 * 3600 * 1000); // UTC-5
const japanTime = new Date(now.getTime() + 9 * 3600 * 1000); // UTC+9
const australiaTime = new Date(now.getTime() + 10 * 3600 * 1000); // UTC+10
const ukTime = new Date(now.getTime() + 0 * 3600 * 1000); // UTC+0
document.getElementById('chinaTime').textContent = chinaTime.toLocaleTimeString();
document.getElementById('usaTime').textContent = usaTime.toLocaleTimeString();
document.getElementById('japanTime').textContent = japanTime.toLocaleTimeString();
document.getElementById('australiaTime').textContent = australiaTime.toLocaleTimeString();
document.getElementById('ukTime').textContent = ukTime.toLocaleTimeString();
}
setInterval(updateTime, 1000);
updateTime();
</script>
</body>
S**t code (
I only added a few countries, and it runs like this
This is just an immature model, and I hope the website can remind users what time it is in other countries. Whether to make this thing into a separate page or put it in a corner, as long as it can remind users.
(It doesn't necessarily have to be the code I wrote; using something else is also fine.🙂)
Q: Why are the minutes and seconds the same?