
/**************************************************************************************
A collection of general purpose Java date and time routines that can easily be modified.
Author: Paul L. Oberholtzer
Date: 30 September 2011

These include:
1. A function to convert a single digit number to a 2 gigit number with a leading 0.
2. A function for a 24 hour clock.
3. A modification of the above to provide a 12 hour AM/PM clock.
4. A function to convert the date to the format: weekday, 2 digit day, month, 4 digit year.
5. A function to start the clock, write the data to the document,  and keep it updating
every 1/2 second (500 milliseconds).
***************************************************************************************/

// A function to convert a single digit to a 2 digit number
function TwoDigit(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}

// 24 hour Clock with seconds display.
function Clock24() 
{
var today=new Date();
var hh=TwoDigit(today.getHours());
var mm=TwoDigit(today.getMinutes());
var ss=TwoDigit(today.getSeconds());
var result = hh+":"+mm+":"+ss;
return result
}

// 12 hour clock without seconds display. 
function Clock12() 
{
var today=new Date();
var hh=today.getHours();
// Convert to 12 hour clock.
var ss = (hh < 12) ? "AM" : "PM" ;
if ( hh > 12 ) hh = hh - 12 ;
if ( hh == 0 ) hh = 12;
hh=TwoDigit(hh);
var mm=TwoDigit(today.getMinutes());
var result = hh+":"+mm+" "+ss;
return result
}

function TodayNow() 
{
var now = new Date();
// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
// Array list of months.
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = now.getDate();
date = TwoDigit(date);
today = days[now.getDay()] + ", " + date + " " + months[now.getMonth()] + " " + now.getFullYear() ;
return today
}

function StartTime()
{
document.getElementById('TimeDisplay').innerHTML=Clock12();
document.getElementById('DateDisplay').innerHTML=TodayNow();
t=setTimeout('StartTime()',1000);
}

