Status Bar Digital Clock

Check out the Time in the Status Line at the bottom left. This example is almost identical to the time example we saw when we looked at when we discussed the ternary operator. (Previous Example explained)

<SCRIPT>

function showTime() {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();

        var timeStr = "" + ((hours > 12) ? hours - 12 : hours);

        timeStr += ((minutes < 10) ? ":0" : ":") + minutes;
        timeStr += ((seconds < 10) ? ":0" : ":") + seconds;
        timeStr += (hours >= 12) ? " P.M." : " A.M.";

        status = timeStr; // time is displayed in the Status Line

        setTimeout("showTime()", 1000);
}

</SCRIPT>

<BODY onLoad="showTime()">