0

Can anyone help me for this, i want to add another timezone to this script like London (UTC+00), Hong Kong (UTC+8), Paris (UTC+1), Tokyo (UTC+9), and else . Thank you

<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>
nyanko070
  • 13
  • 1

1 Answers1

2

It looks like you are attempting to reimplement the toLocaleTimeString method available in most modern browsers.

I would suggest the following modification to your code:

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();
Sigoy
  • 68
  • 5