mozilla

Revision 87638 of Date.prototype.toTimeString()

  • Revision slug: JavaScript/Reference/Global_Objects/Date/toTimeString
  • Revision title: toTimeString
  • Revision id: 87638
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment 12 words added, 1 words removed; page display name reset to default

Revision Content

Returns the time portion of a Date object in human readable form in American English.

Property of Math
Implemented in JavaScript ?
ECMAScript Edition ECMAScript 3rd Edition

Syntax

date.toTimeString()

Description

Date instances refer to a specific point in time. Calling toString will return the date formatted in a human readable form in American English. In SpiderMonkey, this consists of the date portion (day, month, and year) followed by the time portion (hours, minutes, seconds, and time zone). Sometimes it is desirable to obtain a string of the time portion; such a thing can be accomplished with the toTimeString method.

The toTimeString method is especially useful because compliant engines implementing ECMA-262 may differ in the string obtained from toString for Date objects, as the format is implementation-dependent; simple string slicing approaches may not produce consistent results across multiple engines.

Example

Example: A basic usage of toTimeString

var d = new Date(1993, 6, 28, 14, 39, 7);
println(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
println(d.toTimeString()); // prints 14:39:07 GMT-0600 (PDT)

See also

Revision Source

<p>Returns the time portion of a <code>Date</code> object in human readable form in American English.</p>
<table class="standard-table"> <thead> <tr> <th class="header" colspan="2">Property of <a href="/en/JavaScript/Reference/Global_Objects/Math" title="en/JavaScript/Reference/Global_Objects/Math"><code>Math</code></a></th> </tr> </thead> <tbody> <tr> <td>Implemented in</td> <td>JavaScript ?</td> </tr> <tr> <td>ECMAScript Edition</td> <td>ECMAScript 3rd Edition</td> </tr> </tbody>
</table>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<p><code><em>date</em>.toTimeString()</code></p>
<h3 id="Description" name="Description">Description</h3>
<p><a href="/en/JavaScript/Reference/Global_Objects/Date" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date">Date</a> instances refer to a specific point in time. Calling <a href="/en/JavaScript/Reference/Global_Objects/Date/toString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toString">toString</a> will return the date formatted in a human readable form in American English. In <a href="/en/SpiderMonkey" title="en/SpiderMonkey">SpiderMonkey</a>, this consists of the date portion (day, month, and year) followed by the time portion (hours, minutes, seconds, and time zone). Sometimes it is desirable to obtain a string of the time portion; such a thing can be accomplished with the <code>toTimeString</code> method.</p>
<p>The <code>toTimeString</code> method is especially useful because compliant engines implementing <a href="/en/ECMAScript" title="en/ECMAScript">ECMA-262</a> may differ in the string obtained from <code>toString</code> for <code>Date</code> objects, as the format is implementation-dependent; simple string slicing approaches may not produce consistent results across multiple engines.</p>
<h3 id="Example" name="Example">Example</h3>
<h3 id="Example:_A_basic_usage_of_toTimeString" name="Example:_A_basic_usage_of_toTimeString">Example: A basic usage of <code>toTimeString</code></h3>
<pre class="eval">var d = new Date(1993, 6, 28, 14, 39, 7);
println(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
println(d.toTimeString()); // prints 14:39:07 GMT-0600 (PDT)
</pre>
<h3 id="See_also" name="See_also">See also</h3>
<ul> <li><a href="/en/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toLocaleTimeString">toLocaleTimeString</a></li> <li><a href="/en/JavaScript/Reference/Global_Objects/Date/toDateString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toDateString">toDateString</a></li> <li><a href="/en/JavaScript/Reference/Global_Objects/Date/toString" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date/toString">toString</a></li>
</ul>
Revert to this revision