<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>时间转换DEMO</title>
</head>
<body>
<table width="304" border="1">
<tr>
<td width="60">时间1</td>
<td width="228" class="timestamp">1706422071</td>
</tr>
<tr>
<td>时间2</td>
<td class="timestamp">1706622374</td>
</tr>
<tr>
<td>时间3</td>
<td class="timestamp">1707442074</td>
</tr>
</table>
<script>
//根据全球不同时区格式化时间
const timestamps = document.querySelectorAll('.timestamp');
timestamps.forEach((element) => {
let date = new Date(element.textContent * 1000);
let options = { hour12: false, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' };
let dateTimeFormat = new Intl.DateTimeFormat('default', options);
let localTime = dateTimeFormat.format(date);
element.textContent = localTime;
});
</script>
</body>
</html>