JavaScript - Timezones??
I'm trying to build a website in javascript displaying different timezones in Canada. I'm still learning, but I don't know what I'm doing wrong here. The second clock is not displaying at all. =S
Code: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title>ooo</title> </head> <script type="text/javascript"> function init ( ) { timeDisplay = document.createTextNode ( "" ); document.getElementById("clock").appendChild ( timeDisplay ); } function updateClock1 ( ) { var currentTime = new Date ( ); var currentHours = currentTime.getHours ( ); var currentMinutes = currentTime.getMinutes ( ); var currentSeconds = currentTime.getSeconds ( ); currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes; currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds; var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM"; currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours; currentHours = ( currentHours == 0 ) ? 12 : currentHours; var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay; document.getElementById("clock1").firstChild.nodeValue = currentTimeString; } function updateClock2 ( ) { var currentTime = new Date ( ); var currentHours = currentTime.getHours ( )+1; var currentMinutes = currentTime.getMinutes ( ); var currentSeconds = currentTime.getSeconds ( ); currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes; currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds; var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM"; currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours; currentHours = ( currentHours == 0 ) ? 12 : currentHours; var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay; document.getElementById("clock2").firstChild.nodeValue = currentTimeString; } </script> </head> <body onload="updateClock1(); setInterval('updateClock1()', 1000 );"updateClock2(); setInterval('updateClock2()', 1000 )"> <h1>Canadian Timezones</h1> <div> The current time in Vancouver is <span id="clock1"> </span> </div> <div> The current time in Calgary is <span id="clock2"> </span> </div> </body> </html> Similar TutorialsHi All, Not sure if you can help, I'm having some issues with a count down timer that outputs a time until deadline. It was all working fine however since the clocks have gone back in the UK it is a hour out. However I was under the impression that the UTCHours called GMT time with the clocks going forward & backwards. - if this is not the case how do I call the correct GMT time or the server time? The server time is correct however the script displays the wrong message. Here is the script: [JavaScript] var lastimage = ""; function checkTimer() { function b(a, b, c) { - Pastebin.com Thanks! |