aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/date/toisostring/index.html
blob: 45452bcda66fee92af416049d84927b59e989823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
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
---
<div>{{JSRef}}</div>

<p>Die <strong><code>toISOString()</code></strong> Methode gibt einen String im einfach erweitertem ISO format (<a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a>) zurück, welcher immer 24 oder 27 Zeichen lang ist (<strong><code>YYYY-MM-DDTHH:mm:ss.sssZ</code></strong> oder <strong><code>±YYYYYY-MM-DDTHH:mm:ss.sssZ</code></strong>). Die Zeitzone ist immer 0 UTC, wie es durch den Suffix "<code>Z</code>" angedeutet wird.</p>

<div>{{EmbedInteractiveExample("pages/js/date-toisostring.html")}}</div>



<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox"><code><var>dateObj</var>.toISOString()</code>
</pre>

<h3 id="Rückgabewert">Rückgabewert</h3>

<p>Ein String, der das gegebene {{jsxref("Date")}} Objekt im <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> Format bezüglich der Weltzeit (UTC) repräsentiert.</p>

<h2 id="Beispiele">Beispiele</h2>

<h3 id="Using_toISOString()">Using <code>toISOString()</code></h3>

<pre class="brush: js">var today = new Date('05 October 2011 14:48 UTC');

console.log(today.toISOString()); // Returns 2011-10-05T14:48:00.000Z
</pre>

<p>Das obere Beispiel nutzt das Einlesen eines nicht standartisierten String Wert, welcher in nicht-Mozilla Browsern manchmal nicht richtig eingelesen wird.</p>

<h2 id="Polyfill">Polyfill</h2>

<p>Die Methode wurde in ECMA-262 5th edition standartisiert. In Umgebungen, die diese Methode nicht unterstützen (z. B. weil sie nicht aktualisiert werden), kann folgende Methode genutzt werden:</p>

<pre class="brush: js">if (!Date.prototype.toISOString) {
  (function() {

    function pad(number) {
      if (number &lt; 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';
    };

  }());
}
</pre>

<h2 id="Spezifikationen">Spezifikationen</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Spezifikation</th>
   <th scope="col">Status</th>
   <th scope="col">Kommentar</th>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.9.5.43', 'Date.prototype.toISOString')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td>Initiale Definition. Implementiert in JavaScript 1.8.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-date.prototype.toisostring', 'Date.prototype.toISOString')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-date.prototype.toisostring', 'Date.prototype.toISOString')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browserkompatibilität">Browserkompatibilität</h2>

<p>{{Compat("javascript.builtins.Date.toISOString")}}</p>

<h2 id="Siehe_auch">Siehe auch</h2>

<ul>
 <li>{{jsxref("Date.prototype.toLocaleDateString()")}}</li>
 <li>{{jsxref("Date.prototype.toTimeString()")}}</li>
 <li>{{jsxref("Date.prototype.toUTCString()")}}</li>
</ul>