Javascript - Date Time Component Methods

Introduction

The following table lists methods of the Date type for getting and setting specific parts of the date value.

Method
Description
getTime()
Returns the milliseconds representation of the date; same as valueOf().
setTime(milliseconds)
Sets the milliseconds representation of the date, thus changing the entire date.
getFullYear()
Returns the four-digit year (2007 instead of just 07).
getUTCFullYear()
Returns the four-digit year of the UTC date value.
setFullYear(year)

Sets the year of the date. The year must be given with four digits
(2007 instead of just 07).
setUTCFullYear(year)

Sets the year of the UTC date. The year must be given with four
digits (2007 instead of just 07).
getMonth()

Returns the month of the date, where 0 represents January and 11
represents December.
getUTCMonth()

Returns the month of the UTC date, where 0 represents January and
11 represents December.
setMonth(month)

Sets the month of the date, which is any number 0 or greater.
Numbers greater than 11 add years.
setUTCMonth(month)

Sets the month of the UTC date, which is any number 0 or greater.
Numbers greater than 11 add years.
getDate()
Returns the day of the month (1 through 31) for the date.
getUTCDate()
Returns the day of the month (1 through 31) for the UTC date.
setDate(date)

Sets the day of the month for the date. If the date is greater than the
number of days in the month, the month value also gets increased.
setUTCDate(date)


Sets the day of the month for the UTC date. If the date is greater
than the number of days in the month, the month value also gets
increased.
getDay()

Returns the date's day of the week as a number (where 0 represents
Sunday and 6 represents Saturday).
getUTCDay()

Returns the UTC date's day of the week as a number (where 0
represents Sunday and 6 represents Saturday).
getHours()
Returns the date's hours as a number between 0 and 23.
getUTCHours()
Returns the UTC date's hours as a number between 0 and 23.
setHours (hours)

Sets the date's hours. Setting the hours to a number greater than 23
also increments the day of the month.
setUTCHours(hours)

Sets the UTC date's hours. Setting the hours to a number greater
than 23 also increments the day of the month.
getMinutes()
Returns the date's minutes as a number between 0 and 59.
getUTCMinutes()
Returns the UTC date's minutes as a number between 0 and 59.
setMinutes(minutes)

Sets the date's minutes. Setting the minutes to a number greater
than 59 also increments the hour.
setUTCMinutes(minutes)

Sets the UTC date's minutes. Setting the minutes to a number greater
than 59 also increments the hour.
getSeconds()
Returns the date's seconds as a number between 0 and 59.
getUTCSeconds()
Returns the UTC date's seconds as a number between 0 and 59.
setSeconds(seconds)

Sets the date's seconds. Setting the seconds to a number greater
than 59 also increments the minutes.
setUTCSeconds(seconds)

Sets the UTC date's seconds. Setting the seconds to a number
greater than 59 also increments the minutes.
getMilliseconds()
Returns the date's milliseconds.
getUTCMilliseconds()
Returns the UTC date's milliseconds.
setMilliseconds
(milliseconds)
Sets the date's milliseconds.

setUTCMilliseconds
(milliseconds)
Sets the UTC date's milliseconds.

getTimezoneOffset()


Returns the number of minutes that the local time zone is off set from
UTC. For example, Eastern Standard Time returns 300. This value
changes when an area goes into Daylight Saving Time.