From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/date/todatestring/index.html | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/date/todatestring/index.html (limited to 'files/ja/web/javascript/reference/global_objects/date/todatestring') diff --git a/files/ja/web/javascript/reference/global_objects/date/todatestring/index.html b/files/ja/web/javascript/reference/global_objects/date/todatestring/index.html new file mode 100644 index 0000000000..397ca3a281 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/date/todatestring/index.html @@ -0,0 +1,84 @@ +--- +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 +--- +
{{JSRef}}
+ +

toDateString() メソッドは、 {{jsxref("Date")}} オブジェクトの日付部分を英語の次の書式で空白区切りで返します。

+ +
    +
  1. 曜日名の最初の3文字
  2. +
  3. 月名の最初の3文字
  4. +
  5. 2桁の日、必要であれば左に0埋め
  6. +
  7. 4桁 (以上) の年、必要であれば左に0埋め
  8. +
+ +

例 "Thu Jan 01 1970".

+ +
{{EmbedInteractiveExample("pages/js/date-todatestring.html")}}
+ + + +

構文

+ +
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() メソッドは特に役立ちます。その文字列の表記は実装依存であり、単純に文字列を切り出す方法では、複数のエンジンで一貫した結果を得られない可能性があります。

+ +

+ +

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")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf