A Date object contains a number that denotes a particular instant in time that is accurate to within a millisecond. The number value may also contain NaN, which indicates that the Date object does not represent a valid instant in time.
The prototype for the Date prototype object is the Object prototype object.
Instances of the Date object have no special properties beyond those they inherit from the Date.prototype object.
JavaScript version 1.2 and the ECMAScript standard both mandate additional methods that the Date object should support. These are generally useful when computing year numbers higher than 1999.
The Date object is particularly bug prone in Netscape 2. If this browser version is important, you may need to provide significant amounts of date correcting logic or avoid the use of date values altogether.
<!-- Display time since document loaded ---> <HTML> <HEAD> <SCRIPT> window.myDate1 = new Date(); </SCRIPT> </HEAD> <BODY> <DIV ID="TEXTCELL"> 0000 </DIV> <FORM> <INPUT TYPE="button" VALUE="CLICK ME" onClick="clickMe()"> </FORM> <SCRIPT> function clickMe() { myDate2 = new Date(); myDelta = myDate2 - window.myDate1; document.all.TEXTCELL.innerText = myDelta/1000; } </SCRIPT> </BODY> </HTML>
See also: | Broken down time, Browser version compatibility, Calendar time, Compatibility strategies, Date.Class, Date.length, Date.prototype, Event.timeStamp, java.util.Date, JellyScript, MakeDate(), MakeDay(), MakeTime(), Native object, Object object, Time range, Time value, TimeClip(), unwatch(), watch() |
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
constructor | 1.1 ![]() | 1.0 ![]() | 3.0 ![]() | 3.02 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
length | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | ReadOnly, DontEnum. |
prototype | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | ReadOnly, DontDelete, DontEnum. |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
getDate() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getDay() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getFullYear() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getHours() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getMilliseconds() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getMinutes() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getMonth() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getSeconds() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getTime() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getTimezoneOffset() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | ![]() |
getUTCDate() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getUTCDay() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getUTCFullYear() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | ![]() |
getUTCHours() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getUTCMilliseconds() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getUTCMinutes() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getUTCMonth() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getUTCSeconds() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
getVarDate() | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
getYear() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | ![]() |
parse() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setDate() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setFullYear() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setHours() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setMilliseconds() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setMinutes() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setMonth() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setSeconds() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setTime() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setUTCDate() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setUTCFullYear() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setUTCHours() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setUTCMilliseconds() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setUTCMinutes() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setUTCMonth() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setUTCSeconds() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
setYear() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | ![]() |
toDateString() | 1.5 ![]() | 5.5 ![]() | 6.0 ![]() | 5.5 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
toGMTString() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | ![]() |
toLocaleDateString() | 1.5 ![]() | 5.5 ![]() | 6.0 ![]() | 5.5 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
toLocaleString() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
toLocaleTimeString() | 1.5 ![]() | 5.5 ![]() | 6.0 ![]() | 5.5 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
toSource() | 1.3 ![]() | 3.0 ![]() | 4.06 ![]() | 4.0 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
toString() | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | ![]() |
toTimeString() | 1.5 ![]() | 5.5 ![]() | 6.0 ![]() | 5.5 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
toUTCString() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
valueOf() | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
ECMA 262 edition 2 - section - 10.1.5
ECMA 262 edition 2 - section - 15.9
ECMA 262 edition 2 - section - 15.9.6
ECMA 262 edition 3 - section - 10.1.5
ECMA 262 edition 3 - section - 15.9
O'Reilly JavaScript Definitive Guide - page - 48
Prev | Home | Next |
Date number | Up | Date() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |