EchoEcho.Com Homepage
Web Hosting - As Reliable As It Gets!
   Home > References > JavaScript > Date Object


 Tutorials 
 D-Zine Articles 
 Online Tools 
 Free Resources 
 References 
 Quiz 
 Hosting 

















  JavaScript Objects :
DATE OBJECT








Core ObjectNNIEECMA
 Date Date and time object.2+3+ECMA 1
 
MethodsNNIEECMA
 getDate() Date as an integer between 1 and 31.2+3+ECMA 1
 getDay() Day of week value: 0=Sunday, 1=Monday...2+3+ECMA 1
 getFullYear() 4 digit year of a Date object.4+4+ECMA 1
 getHours() Hours value of a Date object (0-23).2+3+ECMA 1
 getMilliseconds() Milliseconds value of a Date object (0-999)4+4+ECMA 1
 getMinutes() Minutes value of a Date object (0-59)2+4+ECMA 1
 getMonth() Month value of a Date object. (0=Jan, 11=Dec)2+3+ECMA 1
 getSeconds() Seconds value of a Date object. (0-59)2+3+ECMA 1
 getTime() Milliseconds since 1970-1-1 of a Date object.2+3+ECMA 1
 getTimezoneOffset() Minutes between local and UTC (GMT) time.2+3+ECMA 1
 getUTCDate() Date value using UTC (GMT) time. (1-31)4+4+ECMA 1
 getUTCDay() Day of week using UTC (GMT) time. (0=Sunday)4+4+ECMA 1
 getUTCFullYear() 4 digit year using UTC (GMT) time.4+4+ECMA 1
 getUTCHours() Hours using UTC (GMT) time. (0-23)4+4+ECMA 1
 getUTCMilliseconds() Milliseconds using UTC (GMT) time. (0-999)4+4+ECMA 1
 getUTCMinutes() Minutes using UTC (GMT) time. (0-59)4+4+ECMA 1
 getUTCMonth() Month using UTC (GMT) time. (0-11).4+4+ECMA 1
 getUTCSeconds() Seconds using UTC (GMT) time. (0-59)4+4+ECMA 1
 getVarDate() Visual Basic compatible VT_DATE value.n/a4+n/a
 getYear() Year value of a Date object.2+3+ECMA 1
 parse() Milliseconds between parsed string and 1970-1-12+3+ECMA 1
 setDate() Sets the date of the Date object.2+4+ECMA 1
 setFullYear() Sets the year value in a Date object.4+4+ECMA 1
 setHours() Sets the hours value in a Date object.2+4+ECMA 1
 setMilliseconds() Sets the milliseconds value in a Date object.4+4+ECMA 1
 setMinutes() Sets the minutess value in a Date object.2+3+ECMA 1
 setMonth() Sets the month value in a Date object.2+3+ECMA 1
 setSeconds() Sets the seconds value in a Date object.2+3+ECMA 1
 setTime() Sets the time value (milliseconds) in a Date object.2+3+ECMA 1
 setUTCDate() Sets the UTC date of a Date object.4+4+ECMA 1
 setUTCFullYear() Sets the UTC year value in a Date object.4+4+ECMA 1
 setUTCHours() Sets the UTC hours value in a Date object.4+4+ECMA 1
 setUTCMilliseconds() Sets the UTC milliseconds value in a Date object.4+4+ECMA 1
 setUTCMinutes() Sets the UTC minutess value in a Date object.4+4+ECMA 1
 setUTCMonth() Sets the UTC month value in a Date object.4+4+ECMA 1
 setUTCSeconds() Sets the UTC seconds value in a Date object.4+4+ECMA 1
 setYear() Sets the year value of a Date object.2+3+ECMA 1
 toDateString() Returns a date as a string value.n/a5.5+n/a
 toGMTString() String value of a Date objects GMT time.2+3+ECMA 1
 toLocaleDateString() Returns a date as a string value.n/a5.5+n/a
 toLocaleString() String value of a Date object, in local time format.2+3+ECMA 1
 toLocaleTimeString() Returns a time as a string value.n/a5.5+n/a
 toSource() String representing the source code of the object.4+n/aECMA 1
 toString() String representation of a Date object2+4+ECMA 1
 toTimeString() Returns a time as a string value.n/a5.5+n/a
 toUTCString() Date converted to string using UTC.4+4+ECMA 1
 UTC() Milliseconds since 1970 using UTC time.2+3+ECMA 1
 valueOf() Milliseconds since 1970-1-1.2+4+ECMA 1
 
PropertiesNNIEECMA
 constructor Reference to the function that created an object.2+4+ECMA 1
 prototype Creates a new method for Date objects2+4+ECMA 1





 Date Core object 
 Date and time object.
 
Syntax:

Syntax 1
  var myDate = new Date()


Syntax 2
  var myDate = new Date([parameters])


Syntax 3
  var myDate = new Date(dateString)


Syntax 4
  var myDate = new Date("month dd, yyyy")


Syntax 5
  var myDate = new Date("month dd, yyyy hh:mm:ss")


Syntax 6
  var myDate = new Date(yy, mm, dd)


Syntax 7
  var myDate = new Date(yy, mm, dd, hh, mm, ss)


Syntax 8
  var myDate = new Date("miliseconds")

 
Browser support:
 Microsoft Internet Explorer: 3+
 Netscape Browser: 2+
 
Implementations:
 JavaScript 1.0 (by Netscape)
 JScript 1 (by Microsoft)
 ECMA Script 1 (ECMA Standard)
 
 
Example:

Example 1 :

  var myDate=new Date();
  alert('Right now it is: '+myDate.toLocaleString());


Example 2 :

  myDate = new Date("October 13, 1966 13:35:00");
  weekdays=new Array('Sun','Mon','Tues','Wednes','Thurs','Fri','Satur');
  alert('I was born a '+weekdays[myDate.getDay()]+'day.');


Example 3 :

  // Note: October is month number 9! (Cause January is 0)
  // The reason for this is that it fits well for Arrays,
  // cause first item in an Array is item number zero.
  // Look at this example:
 
  myDate = new Date(1966,9,13);
  months=new Array('Jan','Feb','Mar','Apr','May','June',
  'July','Aug','Sep','Oct','Nov','Dec');
  alert('I was born in '+months[myDate.getMonth()]);


Example 4 :

  myDate = new Date(1966,9,13,13,35,0);
  nowDate = new Date();
  milliseconds=nowDate.getTime()-myDate.getTime();
  days=Math.floor(milliseconds/(1000*60*60*24));
  alert('I have lived for '+days+' days.');


Example 5 :

  myDate = new Date(1966,9,13,13,35,0);
  nowDate = new Date();
  milliseconds=nowDate.getTime()-myDate.getTime();
  hours=Math.floor(milliseconds/(1000*60*60));
  alert('I have lived for '+hours+' hours.');


Example 6 :

  nowDate = new Date();
  xmasDate = new Date(nowDate.getYear(),11,24);
  milliseconds=xmasDate.getTime()-nowDate.getTime();
  days=Math.floor(milliseconds/(1000*60*60*24));
  alert('There are '+days+' days left till christmas eve.');



















DEVELOPER TIP!
FACT:
Changing the <FONT> tag does not affect the color of your links.
TIP:
Unless you place the <FONT> tag between the <A href> and the </A> tags of your link.





     "Better Than Books - As Easy As It Gets!"


On EchoEcho: D-Zine Articles | Tutorials | Online Tools | Free Resources | References | Quiz | HostingAbout EchoEcho