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

toISOString() メソッドは、簡潔な拡張表記の ISO 形式 (ISO 8601) の文字列を返します。これは、常に 24 文字または 27 文字の長さになります (それぞれ、YYYY-MM-DDTHH:mm:ss.sssZ または ±YYYYYY-MM-DDTHH:mm:ss.sssZ)。タイムゾーンは常に 0 UTC オフセットになり、接尾辞 "Z" で表記されます。

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

構文

+ +
dateObj.toISOString()
+ +

返値

+ +

協定世界時に基づき、与えられた日付を ISO 8601 形式で表す文字列。

+ +

ポリフィル

+ +

このメソッドは、ECMA-262 第 5 版で標準化されました。このメソッドに対応するため、更新されていないエンジンでは、次のコードを用いてこのメソッドの欠落を補うことができます。

+ +
if (!Date.prototype.toISOString) {
+  (function() {
+
+    function pad(number) {
+      if (number < 10) {
+        return '0' + number;
+      }
+      return number;
+    }
+
+    Date.prototype.toISOString = function() {
+      return this.getUTCFullYear() +
+        '-' + pad(this.getUTCMonth() + 1) +
+        '-' + pad(this.getUTCDate()) +
+        'T' + pad(this.getUTCHours()) +
+        ':' + pad(this.getUTCMinutes()) +
+        ':' + pad(this.getUTCSeconds()) +
+        '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
+        'Z';
+    };
+
+  })();
+}
+
+ +

+ +

toISOString() の使用

+ +
let today = new Date('05 October 2011 14:48 UTC')
+
+console.log(today.toISOString())  // 2011-10-05T14:48:00.000Z を返す
+
+ +

上記の例は、Mozilla 以外のブラウザーでは正しく解析されない、非標準の文字列値を解析するのに使います。

+ +

仕様書

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

ブラウザーの互換性

+ + + +

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

+ +

関連情報

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