Date object (Object/core)

An object of the class "Date".

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise Server - 2.0
Opera - 3.0
JavaScript syntax:-myDate = Date
NmyDate = myEvent.timeStamp
NmyDate = myMouseEvent.timeStamp
NmyDate = myMutationEvent.timeStamp
NmyDate = myUIEvent.timeStamp
-myDate = new Date()
Object properties:constructor, length, prototype
Class methods:parse(), UTC()
Object methods:getDate(), getDay(), getFullYear(), getHours(), getMilliseconds(), getMinutes(), getMonth(), getSeconds(), getTime(), getTimezoneOffset(), getUTCDate(), getUTCDay(), getUTCFullYear(), getUTCHours(), getUTCMilliseconds(), getUTCMinutes(), getUTCMonth(), getUTCSeconds(), getVarDate(), getYear(), parse(), setDate(), setFullYear(), setHours(), setMilliseconds(), setMinutes(), setMonth(), setSeconds(), setTime(), setUTCDate(), setUTCFullYear(), setUTCHours(), setUTCMilliseconds(), setUTCMinutes(), setUTCMonth(), setUTCSeconds(), setYear(), toDateString(), toGMTString(), toLocaleDateString(), toLocaleString(), toLocaleTimeString(), toSource(), toString(), toTimeString(), toUTCString(), valueOf()

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.

Warnings:

Example code:

   <!-- 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()

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
constructor1.1 1.11.0 1.03.0 3.03.02 3.02 n/a n/a2 2 n/a n/a n/a-
length1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/aReadOnly, DontEnum.
prototype1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.02.0 2.02 2 n/a n/a n/aReadOnly, DontDelete, DontEnum.

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
getDate()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
getDay()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
getFullYear()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getHours()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
getMilliseconds()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getMinutes()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
getMonth()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
getSeconds()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
getTime()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
getTimezoneOffset()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/aWarning
getUTCDate()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getUTCDay()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getUTCFullYear()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/aWarning
getUTCHours()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getUTCMilliseconds()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getUTCMinutes()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getUTCMonth()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getUTCSeconds()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
getVarDate() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
getYear()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/aWarning , Deprecated
parse()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
setDate()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
setFullYear()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setHours()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
setMilliseconds()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setMinutes()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
setMonth()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
setSeconds()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
setTime()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
setUTCDate()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setUTCFullYear()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setUTCHours()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setUTCMilliseconds()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setUTCMinutes()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setUTCMonth()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setUTCSeconds()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
setYear()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/aWarning , Deprecated
toDateString()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
toGMTString()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/aWarning , Deprecated
toLocaleDateString()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
toLocaleString()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
toLocaleTimeString()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
toSource()1.3 1.33.0 3.04.06 4.064.0 4.0 n/a n/a3 3 n/a n/a n/a-
toString()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/aWarning
toTimeString()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
toUTCString()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a2 2 n/a n/a n/a-
valueOf()1.1 1.13.0 3.03.0 3.04.0 4.0 n/a n/a2 2 n/a n/a n/a-

Cross-references:

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