Can someone point me to a script where it can show the local time in your country as I am running a LOCAL website (our area)?? If there isn't any.. can someone pls recomment a good time and date script that can be easily customized. thanks! any help would be appreciated.
PHP Code: echo date("l, F d, Y H:i:s" ); Should do the trick It will show the local time on the Users's PC regardless of where they are.
No... that is server time. To show user's local time, they need to set their timezone, or you could try guess it by a combination of IP->country lookups etc. Of course, you could use Javascript: d = new Date(); d.toLocaleString(); // local time Code (markup):
Use a GMToffset variable, and the .getTimezoneOffset() method of the JavaScript date object. The code will always display "local" time, regardless of the user's time zone, and provided that the user's system clock is reasonably accurate. You will also have to change the offset variable,whenever the "local" time changes, due to DST. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Any Title</title> <script type="text/javascript"> var GMToffset = -4; //Your CURRENT local offset, whether Daylight or Standard time. function dispClock(){ var PM = false; var refDate = new Date(); refDate.setHours(GMToffset+refDate.getHours()+refDate.getTimezoneOffset()/60); document.getElementById('localDay').innerHTML = refDate.toString().substring(0,3); document.getElementById('localDate').innerHTML = refDate.toString().substring(4,7)+" "+refDate.getDate()+" "+refDate.getFullYear(); var nHours = refDate.getHours().toString(); var nMins = refDate.getMinutes().toString(); if (nMins < 10){nMins = "0"+nMins} if (nHours > 12){nHours = nHours-12; PM=true} var timeStr = nHours+":"+nMins; if (PM){timeStr += " PM"} if (!PM && nHours != 12){timeStr += " AM"} if (!PM && nHours == 12){timeStr += " PM"} document.getElementById('localTime').innerHTML = timeStr; setTimeout("dispClock()",60000); } onload=dispClock; </script> </head> <body> <table border='1' align='center' cellspacing='0' cellpadding='5' style='font-size:14pt'> <thead> <tr> <th> Location </th> <th> Day </th> <th> Date </th> <th> Time </th> </tr> </thead> <tr> <td align='center'> Boston, MA </td> <td id='localDay' align='center'></td> <td id='localDate' align='center'></td> <td id='localTime' align='center'></td> </tr> </table> </body> </html> Code (markup):