﻿/* showDateTime() function extracts the current time hours, minutes and seconds and then displays them in the div with showDateTime id from the BODY section along with the current calendar date information CHROME, FF & IE tested */

function showDateTime(){
    var datetime=new Date();
    var hours=datetime.getHours();
    var minutes=datetime.getMinutes();
    var seconds=datetime.getSeconds();
    //set conditions and output for AM or PM instead of military time dispaly
    var dn="AM";
    if (hours>=12){
        dn="PM";
        hours=hours-12;
    }
    if (hours==0){
        hours=12;
    }
    // for a nice disply we'll add a zero before the numbers between 0 and 9
    if (hours<10){
        hours="0" + hours;
    }
    if (minutes<10){
        minutes="0" + minutes;
    }
    if (seconds<10){
        seconds="0" + seconds;
    }
    var d=datetime.getDate();
    var day=datetime.getDay();
    var month=datetime.getMonth();
    var year=datetime.getYear();
    if (year < 1000)
    year+=1900;
    var days=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var months=new Array("January","February","March","April","May","June","July","August","September","Octomber","November","December");
    document.getElementById('showDateTime').innerHTML=days[day]+", "+months[month]+" "+d+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn;
    t=setTimeout('showDateTime()',1000);
    /* setTimeout() JavaScript method is used to call showClock() every 1000 milliseconds (that means exactly 1 second) */
}