Basic JavaScript Date and Time Functions
By Will Bontrager2004-08-12
How To Extract Information From that Date Object
Lots of information can be extracted from a date object. In this tutorial, we'll extract only what we'll need:
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var monthnumber = now.getMonth();
var monthday = now.getDate();
var year = now.getYear();
Notice that the name of the variable containing the date object and a period are followed by the function name. The function extracts the information from the date object and stores it in the variable named on the left of the equal sign.
All of the function names are intuitive except getDate(), which gets the day of the month rather than a date. Do not confuse "getDate()" with "new Date()" — the former, as stated, extracts the day of the month from a date object. The latter creates the date object itself.
Printing the Date and Time
The example near the end of this tutorial demonstrates one method of obtain the date and time and printing it on a web page.
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
