Date.prototype.toString()

  • Revision slug: JavaScript/Reference/Global_Objects/Date/toString
  • Revision title: toString
  • Revision id: 81796
  • Created:
  • Creator: Dikrib
  • Is current revision? No
  • Comment 3 words added

Revision Content

 

Summary

Returns a string representing the specified Date object.

Method of Date
Implemented in: JavaScript 1.0, NES 2.0
ECMA Version: ECMA-262

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 14:36:22 GMT-0700 (Pacific Daylight Time) 1998

See also

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

Revision Source

<p> </p>
<h3 name="Summary">Summary</h3>
<p>Returns a string representing the specified Date object.</p>
<table class="fullwidth-table"> <tbody> <tr> <td class="header" colspan="2">Method of <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date">Date</a></td> </tr> <tr> <td>Implemented in:</td> <td>JavaScript 1.0, NES 2.0</td> </tr> <tr> <td>ECMA Version:</td> <td>ECMA-262</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 14:36:22 GMT-0700 (Pacific Daylight Time) 1998
</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