--- title: Date.prototype.toTimeString() slug: Web/JavaScript/Reference/Global_Objects/Date/toTimeString tags: - Date - JavaScript - Method - Prototype - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Date/toTimeString --- <div>{{JSRef}}</div> <p><strong><code>toTimeString()</code></strong> メソッドは、英語の人間が読める形式で {{jsxref("Date")}} オブジェクトの「時刻」部を返します。</p> <div>{{EmbedInteractiveExample("pages/js/date-totimestring.html","shorter")}}</div> <div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox notranslate"><var>dateObj</var>.toTimeString()</pre> <h3 id="Return_value" name="Return_value">返値</h3> <p>英語の人間が読める形式で、与えられた日付の「時刻」部を表す文字列を返します。</p> <h2 id="Description" name="Description">解説</h2> <p>{{jsxref("Date")}} インスタンスは特定の時点を参照します。{{jsxref("Date.prototype.toString()", "toString()")}} を呼び出すと、英語の人間が読める形式の日付を返します。<a href="/ja/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a> では、この文字列は「日付」部 (日、月、年) と続く「時刻」部 (時、分、秒、タイムゾーン) から成ります。時々、時刻の文字列を得たいことがあるでしょう。そのような場合に、<code>toTimeString()</code> メソッドが使えます。</p> <p><a href="/ja/docs/Web/JavaScript/Language_Resources">ECMA-262</a> に従って実装されたエンジンは、{{jsxref("Date")}} オブジェクトに対して {{jsxref("Date.prototype.toString()", "toString()")}} メソッドから得られる文字列と異なることがあるため、<code>toTimeString()</code> メソッドは特に役立ちます。その文字列の表記は実装依存であり、単純に文字列を切り出す方法では、複数のエンジンで一貫した結果を得られない可能性があります。</p> <h2 id="Examples" name="Examples">例</h2> <h3 id="A_basic_usage_of_toTimeString" name="A_basic_usage_of_toTimeString">toTimeString() の基本的な使い方</h3> <pre class="brush: js notranslate">var d = new Date(1993, 6, 28, 14, 39, 7); console.log(d.toString()); // Wed Jul 28 1993 14:39:07 GMT-0600 (PDT) console.log(d.toTimeString()); // 14:39:07 GMT-0600 (PDT) </pre> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('ESDraft', '#sec-date.prototype.totimestring', 'Date.prototype.toTimeString')}}</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <p>{{Compat("javascript.builtins.Date.toTimeString")}}</p> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li>{{jsxref("Date.prototype.toLocaleTimeString()")}}</li> <li>{{jsxref("Date.prototype.toDateString()")}}</li> <li>{{jsxref("Date.prototype.toString()")}}</li> </ul>