function clock(format) { //I chose a div as the container for the timer, but //it can be an input tag inside a form, or anything //who's displayed content can be changed through //client-side scripting. html_code = '
'; document.write(html_code); Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth() + 1; //Computes the time difference between the client computer and the server. Server_Date = (new Date(2008, 11, 20, 17, 38, 46)).getTime(); Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); tick((Todays_Date - Server_Date), format); } function tick(time_difference, format) { Today = new Date(new Date().getTime() - time_difference); minutes = Today.getMinutes(); if(minutes < 10) minutes = '0' + minutes; seconds = Today.getSeconds(); if(seconds < 10) seconds = '0' + seconds; months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); /* Set GMT */ var hours = Today.getHours(); hours = hours + 6; switch(format) { case 0: document.getElementById('clock').innerHTML = months[Today.getMonth()] + ' ' + Today.getDate() + ', ' + Today.getYear() + ' ' + Today.getHours() + ':' + minutes + ':' + seconds; break; case 1: document.getElementById('clock').innerHTML = Today.getDate() + '-' + (Today.getMonth() + 1) + '-' + Today.getYear() + ' ' + Today.getHours() + ':' + minutes + ':' + seconds; break; default: document.getElementById('clock').innerHTML = "Thailand Time: "+//months[Today.getMonth()] + ' ' + //Today.getDate() + ', ' + //Today.getYear() + ' ' + hours + ':' + minutes + ':' + seconds; } //Recursive call, keeps the clock ticking. setTimeout('tick(' + time_difference + ', ' + format + ');', 1000); }