--- title: Date.prototype.toDateString() slug: Web/JavaScript/Reference/Global_Objects/Date/toDateString tags: - Date - JavaScript - Method - Prototype - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Date/toDateString ---
toDateString()
メソッドは、 {{jsxref("Date")}} オブジェクトの日付部分を英語の次の書式で空白区切りで返します。
例 "Thu Jan 01 1970".
dateObj.toDateString()
与えられた {{jsxref("Date")}} オブジェクトの「日付」部を表す文字列を人間が読める英語の表記で返します。
{{jsxref("Date")}} インスタンスは、特定の時点を参照します。{{jsxref("Date.prototype.toString()", "toString()")}} を呼び出すと、人間が読める英語の表記で日付を返します。SpiderMonkey では、この文字列は「日付」部 (日、月、年) と続く「時刻」部 (時、分、秒、タイムゾーン) からなります。時々、時刻の文字列を得たいことがあるでしょう。そのような場合は {{jsxref("Date.prototype.toTimeString()", "toTimeString()")}} メソッドが使えます。
ECMA-262 に従って実装されたエンジンは、{{jsxref("Date")}} オブジェクトに対して {{jsxref("Date.prototype.toString()", "toString()")}} メソッドから得られる文字列と異なることがあるため、toDateString()
メソッドは特に役立ちます。その文字列の表記は実装依存であり、単純に文字列を切り出す方法では、複数のエンジンで一貫した結果を得られない可能性があります。
var d = new Date(1993, 5, 28, 14, 39, 7); console.log(d.toString()); // logs Mon Jun 28 1993 14:39:07 GMT-0600 (PDT) console.log(d.toDateString()); // logs Mon Jun 28 1993
注: {{jsxref("Date")}} の引数として使用する場合、月は 0 から始まります(よって、 0 は 1 月に、 11 は 12 月 に対応します)。
仕様書 |
---|
{{SpecName('ESDraft', '#sec-date.prototype.todatestring', 'Date.prototype.toDateString')}} |
{{Compat("javascript.builtins.Date.toDateString")}}