Javascript provides three built-in objects with ready-made properties and methods:
The base date for the Date object is 1/1/70, a limitation imposed by the need for cross-platform uniformity. PCs and Macs can work with dates before this but UNIX systems cannot and this is the limiting factor.
The syntax for creating a new date is:
variableName=new Date(parameters)
For example: Today=new Date();
This example retrieves the date from the system clock. The date is made up of the following elements:
| Day | Month | Day | Hours:Minutes:Seconds | Year |
There are many date methods as follows:
| Method | Example | Returns |
| getDate | today.getDate() | 5 |
| getDay | yesterday.getDay() | 2 |
| getHours | Today.getHours() | 5 |
| getMonth | year.getMonth() | 30 |
| getSeconds | Time.getSeconds() | 6 |
| getTime | now.getTime() | 13 |
| getTimeZoneoffset | today.getTimeZoneOffset | |
| getYear | now.getYear | 97 (years since 1900) |
| parse | Date.parse(July 1, 1997 | N/A |
| setDate | now.setDate(6) | N/A |
| setHours | now.setHours(14) | N/A |
| setMinutes | now.setMinutes(50) | N/A |
| setMonth | today.setMonth(7) | N/A |
| setSeconds | today.setSeconds(30) | N/A |
| setTime | today.setTime(yesterday.getTime()) | N/A |
| setYear | today.setYear(97) | N/A |
| toGMTString | yesterday.toGMTString() | Sat, Feb 24 1996 14:28:15 GMT |
| toLocaleString | today.toLocaleString() | 2/25/96 14:28:15 |
| UTC | 96,11,3,0,0,0 | N/A |
The GET methods return an integer representing the part of the date requested. The SET methods set the part of the date to the value of the parameter supplied. PARSE methods interpret date strings and the single TO method converts a date to a GMT value.
Date numbers are all zero-based as follows:
| Date Attribute | Numeric range |
| seconds, minutes | 0-59 |
| hours | 0-23 |
| day (0=Sunday) | 0-6 |
| month (0=January | 0-11 |
| year | 0 + number of years since 1900 |