Platform Support
IE | Mozilla | Netscape | Opera | Safari | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ |
---|
Constructors
Constructor | Action | IE | Mozilla | Netscape | Opera | Safari | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Date Constructor([Number milliseconds,] [String dateString,] [Object yr_num, mo_num, day_num,] [Object hr_num, min_num, sec_num, ms_num]) : Date
Creates a new instance of a Date object.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | ||||||||||||||
Date([Number milliseconds,] [String dateString,] [Object yr_num, mo_num, day_num,] [Object hr_num, min_num, sec_num, ms_num]) : DateCreates a new instance of a Date object. Parameters
Returns
|
Properties
Property | Action | IE | Mozilla | Netscape | Opera | Safari |
---|---|---|---|---|---|---|
constructor
: Function
Specifies the function that creates an object's prototype. Note that the value of this property is a reference to the function
itself, not a string containing the function's name.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
|
||||||
prototype
: Date
Represents the prototype for this class. You can use the prototype to add properties or methods to all instances of a class.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
|
Functions
Method | Action | IE | Mozilla | Netscape | Opera | Safari | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getDate() : Number
Returns the day of the month for the specified date
according to local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getDay() : Number
Returns a number representing the day of the week for the specified date (according to local time).
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getFullYear() : Number
Returns the year of the specified date according to
local time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getHours() : Number
Returns the hour for the specified date according to
local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getMilliseconds() : Number
Returns the number of milliseconds in the specified date
according to local time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getMinutes() : Number
Returns the minutes in the specified date according to
local time.
|
Show Details | 4.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getMonth() : Number
Returns the month (from 0-11) in the specified date according to
local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getSeconds() : Number
Returns the seconds in the specified date according to
local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getTime() : Number
Returns the numeric value corresponding to the time
for the specified date according to universal time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getTimezoneOffset() : Number
Returns the time-zone offset in minutes for the
current locale.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getUTCDate() : Number
Returns the day (date) of the month in the specified
date according to universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getUTCDay() : Number
Returns the day of the week in the specified date
according to universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getUTCFullYear() : Number
Returns the year in the specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getUTCHours() : Number
Returns the hours in the specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getUTCMilliseconds() : Number
Returns the milliseconds in the specified date
according to universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getUTCMinutes() : Number
Returns the minutes in the specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getUTCMonth() : Number
Returns the month of the specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getUTCSeconds() : Number
Returns the seconds in the specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
getYear() : Number
Returns the year in the specified date according to
local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
now() : Number
Returns the number of milliseconds passed since 1970-01-01 00:00:00 UTC.
|
Show Details | no | 1.0+ | no | no | no | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
static parse(String dateString) : Number
Parses a string representation of a date, and returns
the number of milliseconds since January 1, 1970,
00:00:00, local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setDate(Number dayValue) : Number
Sets the day of the month for a specified date
according to local time.
|
Show Details | 4.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setFullYear(Number yearValue, [Number monthValue,] [Number dayValue]) : Number
Sets the full year for a specified date according to
local time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setHours(Number hoursValue, [Number minutesValue,] [Number secondsValue,] [Number msValue]) : Number
Sets the hours for a specified date according to local
time.
|
Show Details | 4.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setMilliseconds(Number millisecondsValue) : Number
Sets the milliseconds for a specified date according
to local time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setMinutes(Number minutesValue, [Number secondsValue,] [Number msValue]) : Number
Sets the minutes for a specified date according to
local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setMonth(Number monthValue, [Number dayValue]) : Number
Set the month for a specified date according to local
time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setSeconds(Number secondsValue, [Number msValue]) : Number
Sets the seconds for a specified date according to
local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setTime(Number timeValue) : Number
Sets the value of a Date object according
to local time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setUTCDate(Number dayValue) : Number
Sets the day of the month for a specified date
according to universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setUTCFullYear(Number yearValue, [Number monthValue,] [Number dayValue]) : Number
Sets the full year for a specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setUTCHours(Number hoursValue, [Number minutesValue,] [Number secondsValue,] [Number msValue]) : Number
Sets the hour for a specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setUTCMilliseconds(Number millisecondsValue) : Number
Sets the milliseconds for a specified date according
to universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setUTCMinutes(Number minutesValue, [Number secondsValue,] [Number msValue]) : Number
Sets the minutes for a specified date according to universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setUTCMonth(Number monthValue, [Number dayValue]) : Number
Sets the month for a specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setUTCSeconds(Number secondsValue, [Number msValue]) : Number
Sets the seconds for a specified date according to
universal time.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
setYear(Number yearValue) : Number
Sets the year for a specified date according to local
time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
toDateString() : String
Returns a string version of the Date object expressed in local time.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
toGMTString() : String
Converts a date to a string, using Internet GMT conventions.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
toLocaleDateString() : String
Converts a date to a string, returning the "date"
portion using the current locale's conventions.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
toLocaleString() : String
Converts a date to a string, using the current
locale's conventions.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
toLocaleTimeString() : String
Converts a date to a string, returning the "date"
portion using the current locale's conventions.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
toSource() : String
Returns a string representing the source code of a Date object.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | no | no | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
toString() : String
Returns a string representing the specified Date
object.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
toTimeString() : String
Returns a string representation of the time portion of a Date object, expressed in local time.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
toUTCString() : String
Converts a date to a string, using the universal time
convention.
|
Show Details | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
|||||||||||||||||||||||||||||
static UTC(Object year, Number month, [Number date,] [Number hrs,] [Number min,] [Number sec,] [Number ms]) : Number
Accepts the same parameters as the longest form of the
constructor, and returns the number of milliseconds in a
Date object since January 1, 1970, 00:00:00,
universal time.
|
Show Details | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Parameters
Returns
|
|||||||||||||||||||||||||||||
valueOf() : Number
Returns the primitive value of a Date object.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | |||||||||||||||||||||||
Returns
|
Several ways to assign dates
The following examples show several ways to assign dates:
today = new Date(); birthday = new Date("December 17, 1995 03:24:00"); birthday = new Date(95,11,17); birthday = new Date(95,11,17,3,24,0);
Remarks
If you supply no arguments, the constructor creates a
Date
object for today's date and time
according to local time. If you supply some arguments but
not others, the missing arguments are set to 0. If you
supply any arguments, you must supply at least the year,
month, and day. You can omit the hours, minutes, seconds,
and milliseconds.
The date is measured in milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.
The Date
object provides uniform behavior
across platforms.
The Date
object supports a number of UTC
(universal) methods, as well as local time methods. UTC,
also known as Greenwich Mean Time (GMT), refers to the
time as set by the World Time Standard. The local time is
the time known to the computer where JavaScript is
executed.
For compatibility with millennium calculations (in
other words, to take into account the year 2000), you
should always specify the year in full; for example, use
1998, not 98. To assist you in specifying the complete
year, JavaScript includes the methods
getFullYear
,
setFullYear
,
getUTCFullYear
, and
setUTCFullYear
.
The following example returns the time elapsed between
timeA
and timeB
in
milliseconds.
timeA = new Date(); // Statements here to take some action. timeB = new Date(); timeDifference = timeB - timeA;
References
Availability
JavaScript 1.0|JScript 1.0|ECMAScript v1