The JavaScript Date Object - The JavaScript Diaries: Part 15 - Page 2 | WebReference

The JavaScript Date Object - The JavaScript Diaries: Part 15 - Page 2


[previous][next]

The JavaScript Diaries: Part 15 - The Date Object

Methods

The Date() object utilizes several methods, which are detailed below. Note that the time is given either according to local time (the time as stated on the visitor's computer) or according to universal time. A few of the methods have been deprecated, and have been marked as such. They are shown here so you will know them if you run into an older script or tutorial.
[ Taken from Core JavaScript Reference 1.5 ]

Name Description
getMilliseconds() Returns the milliseconds in the specified date according to local time. [ 0 - 999 ]
getSeconds() Returns the seconds in the specified date according to local time. [ 0 - 59 ]
getMinutes() Returns the minutes in the specified date according to local time. [ 0 - 59 ]
getHours() Returns the hour in the specified date according to local time. [ 0 - 23 ]
getDay() Returns the day of the week for the specified date according to local time. [ 0 (Sunday) to 6 (Saturday) ]
getDate() Returns the day of the month for the specified date according to local time. [ 1 - 31 ]
getMonth() Returns the month in the specified date according to local time. [ 0 (January) to 11 (December) ]
getYear()
deprecated
Returns the year in the specified date according to local time. (Use getFullYear instead.)
getFullYear() Returns the year of the specified date according to local time.
getTime() Returns the numeric value corresponding to the time for the specified date according to local time.
getTimezoneOffset() Returns the time-zone offset in minutes for the current locale.
   
getUTCMilliseconds() Returns the milliseconds in the specified date according to universal time. [ 0 - 999 ]
getUTCSeconds() Returns the seconds in the specified date according to universal time. [ 0 - 59 ]
getUTCMinutes() Returns the minutes in the specified date according to universal time. [ 0 - 59 ]
getUTCHours() Returns the hours in the specified date according to universal time. [ 0 - 23 ]
getUTCDay() Returns the day of the week in the specified date according to universal time. [ 0 (Sunday) to 6 (Saturday) ]
getUTCDate() Returns the day of the month in the specified date according to universal time. [ 1 - 31 ]
getUTCMonth() Returns the month according in the specified date according to universal time. [ 0 (January) to 11 (December) ]
getUTCFullYear() Returns the year in the specified date according to universal time.
   
setMilliseconds() Sets the milliseconds for a specified date according to local time. [ 0 - 999 ]
setSeconds() Sets the seconds for a specified date according to local time. [ 0 - 59 ]
setMinutes() Sets the minutes for a specified date according to local time. [ 0 - 59 ]
setHours() Sets the hours for a specified date according to local time. [ 0 - 23 ]
setDate() Sets the day of the month for a specified date according to local time. [ 1 - 31 ]
setMonth() Sets the month for a specified date according to local time. [ 0 (January) to 11 (December) ]
setYear()
deprecated
Sets the year for a specified date according to local time. (Use setFullYear instead.)
setFullYear() Sets the full year for a specified date according to local time.
setTime() Sets the value of a Date object according to local time.
   
setUTCMilliseconds() Sets the milliseconds for a specified date according to universal time. [ 0 - 999 ]
setUTCSeconds() Sets the seconds for a specified date according to universal time. [ 0 - 59 ]
setUTCMinutes() Sets the minutes for a specified date according to universal time. [ 0 - 59 ]
setUTCHours() Sets the hour for a specified date according to universal time. [ 0 - 23 ]
setUTCDate() Sets the day of the month for a specified date according to universal time. [ 1 - 31 ]
setUTCMonth() Sets the month for a specified date according to universal time. [ 0 (January) to 11 (December) ]
setYear() Sets the year for a specified date according to local time.
setUTCFullYear() Sets the full year for a specified date according to universal time.
   
toGMTString()
deprecated
Converts a date to a string, using the Internet GMT conventions. (Use toUTCString instead.)
toLocaleString() Converts a date to a string, using the current locale's conventions.
toLocaleDateString() Returns the "date" portion of the Date as a string, using the current locale's conventions.
toLocaleTimeString() Returns the "time" portion of the Date as a string, using the current locale's conventions.
toString() Returns a string representing the specified Date object. Overrides the Object.toString method.
toUTCString() Converts a date to a string, using the universal time convention.
   
parse() Returns the number of milliseconds in a date string since January 1, 1970, 00:00:00, local time.
   
UTC() Returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.
   
toSource() Returns an object literal representing the specified Date object; you can use this value to create a new object. Overrides the Object.toSource method.
   
valueOf() Returns the primitive value of a Date object. Overrides the Object.valueOf method.

[previous][next]

URL: