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/tojson/index.html | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/date/tojson/index.html (limited to 'files/ja/web/javascript/reference/global_objects/date/tojson') diff --git a/files/ja/web/javascript/reference/global_objects/date/tojson/index.html b/files/ja/web/javascript/reference/global_objects/date/tojson/index.html new file mode 100644 index 0000000000..2370dfc2b7 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/date/tojson/index.html @@ -0,0 +1,69 @@ +--- +title: Date.prototype.toJSON() +slug: Web/JavaScript/Reference/Global_Objects/Date/toJSON +tags: + - Date + - JavaScript + - Method + - Prototype + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Date/toJSON +--- +
{{JSRef}}
+ +

toJSON() メソッドは、{{jsxref("Date")}} オブジェクトの文字列表現を返します。

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

構文

+ +
dateObj.toJSON()
+ +

返値

+ +

与えられた日付を表す文字列。

+ +

解説

+ +

{{jsxref("Date")}} インスタンスは、特定の時点を参照します。toJSON() の呼び出しは、{{jsxref("Date")}} オブジェクトの値を表す文字列 ({{jsxref("Date.prototype.toISOString()", "toISOString()")}} を使用) を返します。このメソッドは、一般的に、{{Glossary("JSON")}} シリアライズを目的として {{jsxref("Date")}} オブジェクトをシリアライズするために使用されます。

+ +

+ +

toJSON() を使う

+ +
var jsonDate = (new Date()).toJSON();
+var backToDate = new Date(jsonDate);
+
+console.log(jsonDate); //2015-10-26T07:46:36.611Z
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-date.prototype.tojson', 'Date.prototype.toJSON')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.Date.toJSON")}}

+ +

関連情報

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