Date.toString() (Method)

Return a string primitive version of an object.

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
Property/method value type:String primitive
JavaScript syntax:-myDate.toString()

This method returns a string primitive representation of the date value of the receiving object. The contents of the string are implementation-dependent, but are intended to represent the date in a convenient, human-readable form in the current time zone. This is likely to be a UTC time value but implementations may perform some localization.

Warnings:

Wed Jun 21 20:20:03 UTC 2000

Wed Jun 21 20:20:03 GMT-2300 (2000

Example code:

   <HTML>
   <HEAD>
   </HEAD>
   <BODY>
   <SCRIPT>
   // Define a function that overrides toString()
   function myToString()
   {
   myYear  = this.getFullYear();
   myMonth = this.getMonth()+1;
   myDate  = this.getDate();
   
   return (myDate + "-" + myMonth + "-" + myYear);
   }
   // Register the new function
   Date.prototype.toString = myToString;
   // Create a date and test the replacement Date.toString() method
   myDate = new Date();
   document.write(myDate.toString())
   document.write("<BR>")
   </SCRIPT>
   </BODY>
   </HTML>

See also:Cast operator, Date.prototype, Date.toSource(), toString()

Cross-references:

ECMA 262 edition 2 - section - 15.9.5.2

ECMA 262 edition 3 - section - 15.9.5.2