Date Methods and Examples

METHODS

VALUES

DESCRIPTION

getDate() 1-31 Returns the day of the month from 1 to 31
getDay() 0-6 Returns the day of the week from O to 6
(Sunday = 0, Monday =1, ...)
getHours() 0-23 Returns the hour in military time from 0 to 23
getMinutes() 0-59 Returns the minute from 0 to 59
getMonth() 0-11 Returns the value of the month from O to 11
(January = 0, February =1, ...)
getSeconds() 0-59 Returns the seconds
getTime() 0-… Returns the date as an integer representing the number of milliseconds since January 1st, 1970 at 00:00:00
getTimezoneOffset() 0-…. Returns the difference between the local time and Greenwich Mean Time in minutes.
getYear() 70-… Returns the number of years since 1900 (in other words, 1996 is represented by "96.") This value method is inconsistently applied past the year 1999.
setDate(date) 1-31 Sets the day of the month to the value specified in date
setHours(hour) 0-23 Sets the hour to the value specified in hour
setMinutes(minutes) 0-59 Sets the minute to the value specified in minutes
setMonth(month) 0-11 Sets the month to the value specified in month
setSeconds(seconds) 0-59 Sets the second to the value specified in seconds
setTime(time) 0-… Sets the time using the value specified in time, where time is a variable containing the number of milliseconds since January 1st , 1970 at 00:00:00
setYear(year) 70-… Sets the year to the value specified in year
toGMTString()   Converts the date to a text string in Greenwich Mean Time

 

Examples:

  1. Some different ways of assigning a date object to a variable named "ADay'":

// form new Date("Month, dd, yyyy, hh:mm:ss")
// The month is spelled out with no abbreviations
var ADay = new Date("June, 15, 1995, 14:35:00");

// form new Date (yy, mm, dd, hh, mm, ss)
var ADay = new Date(1997, 5, 15, 14, 35, 0);

// form new Date (yy, mm, dd) Time set set to midnight 00:00:00 here
var ADay = new Date (1998, 7, 27);

  1. You can also create a variable containing the current date and time by removing the parameters from the Data() method.

    var Today = new Date();