mozilla

Revision 81798 of Date.prototype.toString()

  • Revision slug: JavaScript/Reference/Global_Objects/Date/toString
  • Revision title: toString
  • Revision id: 81798
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment 6 words added, 12 words removed

Revision Content

 

Returns a string representing the specified Date object.

Method of Date
Implemented in 1.0
ECMAScript Edition ECMAScript 1st Edition

Syntax

toString()

Parameters

None.

Description

The Date object overrides the toString method of the Object object; it does not inherit Object.toString. For Date objects, the toString method returns a string representation of the object.

toString always returns a string representation of the date in American English.

JavaScript calls the toString method automatically when a date is to be represented as a text value or when a date is referred to in a string concatenation.

Examples

Example: Using toString

The following assigns the toString value of a Date object to myVar:

x = new Date();
myVar=x.toString();   //assigns a value to myVar similar to:
     //Mon Sep 28 1998 14:36:22 GMT-0700 (Pacific Daylight Time)

See also

{{ languages( { "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Date/toString" } ) }}

Revision Source

<p> </p>
<p>Returns a string representing the specified Date object.</p>
<table class="standard-table"> <thead> <tr> <th class="header" colspan="2">Method of <a href="/en/JavaScript/Reference/Global_Objects/Date"><code>Date</code></a></th> </tr> </thead> <tbody> <tr> <td>Implemented in</td> <td>1.0</td> </tr> <tr> <td>ECMAScript Edition</td> <td>ECMAScript 1st Edition</td> </tr> </tbody>
</table> <h3 name="Syntax">Syntax</h3>
<p><code> toString() </code></p>
<h3 name="Parameters">Parameters</h3>
<p>None.</p>
<h3 name="Description">Description</h3>
<p>The <code><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date">Date</a></code> object overrides the <code>toString</code> method of the <code><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Object" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></code> object; it does not inherit <code><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/toString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Object/toString">Object.toString</a></code>. For <code><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date">Date</a></code> objects, the <code>toString</code> method returns a string representation of the object.</p>
<p><code>toString</code> always returns a string representation of the date in American English.</p>
<p>JavaScript calls the <code>toString</code> method automatically when a date is to be represented as a text value or when a date is referred to in a string concatenation.</p>
<h3 name="Examples">Examples</h3>
<h4 name="Example:_Using_toString">Example: Using <code>toString</code></h4>
<p>The following assigns the <code>toString</code> value of a <code>Date</code> object to <code>myVar</code>:</p>
<pre>x = new Date();
myVar=x.toString();   //assigns a value to myVar similar to:
     //Mon Sep 28 1998 14:36:22 GMT-0700 (Pacific Daylight Time)
</pre>
<h3 name="See_also">See also</h3>
<ul> <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/toString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Object/toString">Object.toString</a></li> <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toDateString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toDateString">toDateString</a></li> <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toTimeString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toTimeString">toTimeString</a></li> <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toLocaleString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toLocaleString">toLocaleString</a></li>
</ul>
<p>{{ languages( { "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Date/toString" } ) }}</p>
Revert to this revision