Skip to content

Instantly share code, notes, and snippets.

@1a57danc3
Forked from kyanny/gist:1326893
Created September 11, 2017 05:51
Show Gist options
  • Save 1a57danc3/af8004914ddf9f10914c5a32e7d644a9 to your computer and use it in GitHub Desktop.
Save 1a57danc3/af8004914ddf9f10914c5a32e7d644a9 to your computer and use it in GitHub Desktop.
javascript timezone convert
// http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title></title>
</head>
<body>
<h1></h1>
<div id="local"></div>
<div id="bombay"></div>
<div id="singapore"></div>
<div id="tokyo"></div>
<div id="london"></div>
<script>
function calcTime(city, offset) {
var d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var nd = new Date(utc + (3600000 * offset));
return "The local time in " + city + " is " + nd.toLocaleString();
}
document.getElementById('local').innerHTML = "The local time is " + (new Date()).toLocaleString();
document.getElementById('bombay').innerHTML = calcTime('bombay', '+5.5');
document.getElementById('singapore').innerHTML = calcTime('singapore', '+8');
document.getElementById('tokyo').innerHTML = calcTime('tokyo', '+9');
document.getElementById('london').innerHTML = calcTime('london', '+1');
</script>
<hr>
<address></address>
<!-- hhmts start --> Last modified: Mon Oct 31 02:04:17 BRST 2011 <!-- hhmts end -->
</body> </html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment