﻿function writeTime() {

    // get a date object
    var today = new Date();

    // ask the object for some information
    var hours = today.getHours();
    var minutes = today.getMinutes();
    var seconds = today.getSeconds();
    var theHour = today.getHours();

    minutes = fixTime(minutes);
    seconds = fixTime(seconds);

    // put together the time string and write it out
    if (hours > 12) { hours = hours - 12; timeSuffix = ' PM'; }
    else { timeSuffix = ' AM'; }

    var fixedTime = hours + ":" + minutes + ":" + seconds + timeSuffix;

    document.getElementById("timeBox").innerHTML = fixedTime;

    // run this function again in half a second
    the_timeout = setTimeout('writeTime();', 500);
}

function fixTime(the_time) {
    if (the_time < 10) {
        the_time = "0" + the_time;
    }
    return the_time;
}
