Created
October 31, 2011 04:07
-
-
Save kyanny/1326893 to your computer and use it in GitHub Desktop.
javascript timezone convert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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