This Code will show client side current time.
js_clock();
JavaScript Function:
function js_clock() { var clock_time = new Date(); var clock_hours = clock_time.getHours(); var clock_minutes = clock_time.getMinutes(); var clock_seconds = clock_time.getSeconds(); var clock_suffix = "AM"; if (clock_hours > 11) { clock_suffix = "PM"; clock_hours = clock_hours - 12; } if (clock_hours == 0) { clock_hours = 12; } if (clock_hours < 10) { clock_hours = "0" + clock_hours; } if (clock_minutes < 10) { clock_minutes = "0" + clock_minutes; } if (clock_seconds < 10) { clock_seconds = "0" + clock_seconds; } var clock_div = document.getElementById('js_clock'); clock_div.innerHTML = "<strong>" + clock_hours + ":" + clock_minutes + ":" + clock_seconds + " </strong> " + clock_suffix;setTimeout("js_clock()", 1000); }
You can change the time format as your choice. You can see the demo on my blog header.
Comments
Post a Comment