toDateString() メソッドは、人間が読めるアメリカ英語の表記で Date オブジェクトの「日付」部を返します。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
構文
dateObj.toDateString()
戻り値
与えられた Date オブジェクトの「日付」部を表す文字列を人間が読めるアメリカ英語の表記で返します。
説明
Date インスタンスは、特定の時点を参照します。toString() を呼び出すと、人間が読めるアメリカ英語の表記で日付を返します。SpiderMonkey では、この文字列は「日付」部 (日、月、年) と続く「時刻」部 (時、分、秒、タイムゾーン) からなります。時々、時刻の文字列を得たいことがあるでしょう。そのような場合は toTimeString() メソッドが使えます。
ECMA-262 に従って実装されたエンジンは、Date オブジェクトに対して toString() メソッドから得られる文字列と異なることがあるため、toDateString() メソッドは特に役立ちます。その文字列の表記は実装依存であり、単純に文字列を切り出す方法では、複数のエンジンで一貫した結果を得られない可能性があります。
例
toDateString() の基本的な使い方
var d = new Date(1993, 5, 28, 14, 39, 7); console.log(d.toString()); // logs Wed Jun 28 1993 14:39:07 GMT-0600 (PDT) console.log(d.toDateString()); // logs Wed Jun 28 1993
注: Date の引数として使用する場合、月は 0 から始まります(よって、 0 は 1 月に、 11 は 12 月 に対応します)。
仕様
ブラウザーの実装状況
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| デスクトップ | モバイル | サーバー | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toDateString | Chrome 完全対応 1 | Edge 完全対応 12 | Firefox 完全対応 1 | IE 完全対応 5.5 | Opera 完全対応 あり | Safari 完全対応 あり | WebView Android 完全対応 1 | Chrome Android 完全対応 18 | Firefox Android 完全対応 4 | Opera Android 完全対応 あり | Safari iOS 完全対応 あり | Samsung Internet Android 完全対応 1.0 | nodejs 完全対応 あり |
凡例
- 完全対応
- 完全対応