lovephp Posted November 8, 2012 Share Posted November 8, 2012 Guys this script when i run on my system do not show the time correctly why? our server machine time is not correct so how do it make it to show the PST MST CST correctly even tho the server machine time is not correct? <html> <head> <SCRIPT LANGUAGE="Javascript"> var timerID = null var timerRunning = false function startclock(){ stopclock() showtime() } function stopclock(){ if(timerRunning) clearTimeout(timerID) timerRunning = false } function showtime(){ var now = new Date() var hours = now.getUTCHours() var minutes = now.getUTCMinutes() var seconds = now.getUTCSeconds() var utcTime = "" + (hours) utcTime += ((minutes < 10) ? ":0" : ":") + minutes utcTime += ((seconds < 10) ? ":0" : ":") + seconds if (hours - 8 < 0) { var pstTime = "" + (hours - 8 + 24) } else { var pstTime = "" + (hours - } pstTime += ((minutes < 10) ? ":0" : ":") + minutes pstTime += ((seconds < 10) ? ":0" : ":") + seconds if (hours - 7 < 0) { var mstTime = "" + (hours - 7 + 24) } else { var mstTime = "" + (hours - 7) } mstTime += ((minutes < 10) ? ":0" : ":") + minutes mstTime += ((seconds < 10) ? ":0" : ":") + seconds if (hours - 6 < 0) { var cstTime = "" + (hours - 6 + 24) } else { var cstTime = "" + (hours - 6) } cstTime += ((minutes < 10) ? ":0" : ":") + minutes cstTime += ((seconds < 10) ? ":0" : ":") + seconds if (hours - 5 < 0) { var estTime = "" + (hours - 5 + 24) } else { var estTime = "" + (hours - 5) } estTime += ((minutes < 10) ? ":0" : ":") + minutes estTime += ((seconds < 10) ? ":0" : ":") + seconds document.getElementById("PST").value = pstTime document.getElementById("MST").value = mstTime document.getElementById("CST").value = cstTime document.getElementById("EST").value = estTime document.getElementById("UTC").value = utcTime timerID = setTimeout("showtime()",1000) timerRunning = true } </SCRIPT> <title></title> </head> <body> <center> <b>PST</b> <INPUT TYPE="text" SIZE=11 VALUE ="....Initializing...." id="PST" style="border-style:none;background-color:transparent"> <b>MST</b> <INPUT TYPE="text" SIZE=11 VALUE ="....Initializing...." id="MST" style="border-style:none;background-color:transparent"> <b>CST</b> <INPUT TYPE="text" SIZE=11 VALUE ="....Initializing...." id="CST" style="border-style:none;background-color:transparent"> <b>EST</b> <INPUT TYPE="text" SIZE=11 VALUE ="....Initializing...." id="EST" style="border-style:none;background-color:transparent"> <b>UTC</b> <INPUT TYPE="text" SIZE=11 VALUE ="....Initializing...." id="UTC" style="border-style:none;background-color:transparent"> <img src="1px.png" onload="startclock()"></link> <center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/270462-timezone-do-not-display-correctly/ Share on other sites More sharing options...
Adam Posted November 12, 2012 Share Posted November 12, 2012 Have you taken a look at the documentation for the Date object? You can provide a date string (from the server) to base the date on. Link to comment https://forums.phpfreaks.com/topic/270462-timezone-do-not-display-correctly/#findComment-1391885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.