What methods are available with the date() function?
Get (or set) individual date and time fields.
- getDay() integer value of day of week (0 - 6)
- getUTCDay() integer value of day of week (0 - 6)
- getDate() day of month
- getUTCDate() day of month
- getMonth() month of year (0 - 11)
- getUTCMonth() month of year (0 - 11)
- getFullYear() four digit year
- getUTCFullYear() four digit year
- getHours() hour of day (0 - 23)
- getUTCHours() hour of day (0 - 23)
- getMinutes() minutes into the hour
- getUTCMinutes() minutes into the hour
- getSeconds() seconds into the minute
- getUTCSeconds() seconds into the minute
Entries above containing UTC are Coordinated Universal Time (UTC) while those without are local time. Also available corresponding to all of the above are set functions to change the date and time.
Other Useful Date Methods.
- getTime() milliseconds since midnight 1st January, 1970
- getTimezoneOffset() minutes difference between local time and UTC
- parse() convert a date/time string into milliseconds since midnight 1st January, 1970
- toLocaleString() local date and time in string format
- toString() local date and time in string format
Using the Date Methods.
To use the date methods, you first declare a variable to be a new Date and then reference the date methods with respect to the date so declared. For example:
var now = new Date;
var hourOfDay = now.getHour();
This article written by Stephen Chapman, Felgall Pty Ltd.