谁能帮我这个,我想在这个脚本中添加另一个时区,如伦敦 (UTC+00(、香港 (UTC+8(、巴黎 (UTC+1(、东京 (UTC+9( 等等。谢谢
<script>
function show()
{
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var dn="AM"
if (hours>12){
dn="PM"
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
document.write("Local " + hours+":"+minutes+" "+dn + "<br>");
}
show()
</script>
看起来您正在尝试重新实现大多数现代浏览器中可用的toLocaleTimeString
方法。
我建议对您的代码进行以下修改:
function show()
{
var digital=new Date()
document.write("Local " + digital.toLocaleTimeString("en-US", { hour: "2-digit", minute:"2-digit" }) + "<br>");
document.write("Tokyo " + digital.toLocaleTimeString("en-US", { timeZone: "Asia/Tokyo", hour: "2-digit", minute:"2-digit" }));
}
show();