Basic JavaScript Date and Time Functions
By Will Bontrager2004-08-12
The Time
To get the time, the complete working example further below has a function called getClockTime()
getClockTime() includes code to format the clock time into an "AM" or "PM" representation. The following four lines accomplish that.
var ap = "AM";
if (hour > 11) { ap = "PM"; }
if (hour > 12) { hour = hour - 12; }
if (hour == 0) { hour = 12; }
If you want the clock time to represent a 24-hour clock instead of an "AM/PM" representation, simply remove those four lines from the function.
getClockTime() constructs a string of characters representing the clock time. It then returns that construction to whatever JavaScript code calls the function. If you don't want the construction to include the "AM" or "PM" part, remove the last two lines from the code that constructs the clock time.
Tutorial Pages:
» Basic JavaScript Date and Time Functions
» How To Extract Information From that Date Object
» The Date
» The Time
» The Printing
» The Complete Working Example
Copyright 2004 Bontrager Connection, LLC
