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(); Todays_Month = Today.getMonth() + 1; //Computes the time difference between the client computer and the server. Server_Date = (new Date(2010, 9, 8, 4, 51, 38)).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; days = new Array('Söndag','Måndag','Tisdag','Onsdag','Torsdag','Fredag','Lördag'); months = new Array('Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni', 'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December'); switch(format) { case 0: document.all.clock.innerHTML = "" + Today.getHours() + ':' + minutes + ':' + seconds + " " + days[Today.getDay()] + ' ' + Today.getDate() + ' ' + months[Today.getMonth()] + ' ' + Today.getFullYear() + "
"; break; case 1: document.all.clock.innerHTML = Today.getDate() + '-' + (Today.getMonth() + 1) + '-' + Today.getYear() + ' ' + Today.getHours() + ':' + minutes + ':' + seconds; break; default: document.all.clock.innerHTML = months[Today.getMonth()] + ' ' + Today.getDate() + ', ' + Today.getYear() + ' ' + Today.getHours() + ':' + minutes + ':' + seconds; } //Recursive call, keeps the clock ticking. setTimeout('tick(' + time_difference + ', ' + format + ');', 1000); }