﻿var timerID = null;
var timerRunning = false;
function stopclock() {
    if (timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}
function showtime() {
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var milliseconds = now.getMilliseconds()
    var timeValue = "" + ((hours > 24) ? hours - 24 : hours)
    if (timeValue == "0") timeValue = 24;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes + "<span class='seconds'>"
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds + "</span><span class='milliseconds'>"
    if (milliseconds < 10) {
        timeValue += ".00"
    }
    else {
        if (milliseconds < 100) {
            timeValue += ".0"
        }
        else {
            timeValue += "."
        }
    }
    timeValue += milliseconds + "</span>"
    document.getElementById('clock').innerHTML = timeValue;
    timerID = setTimeout("showtime()", 1);
    timerRunning = true;
}
function startclock() {
    stopclock();
    showtime();
}
window.onload = startclock;
