blob: bbe50ba20e0b63b7ef5cd0866241ab3c06492a8d (
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
|
---
title: Date.prototype.toJSON()
slug: Web/JavaScript/Reference/Global_Objects/Date/toJSON
tags:
- Date
- JavaScript
- Methode(2)
- Prototype
- Referenz
translation_of: Web/JavaScript/Reference/Global_Objects/Date/toJSON
---
<div>{{JSRef}}</div>
<p>Die <strong><code>toJSON()</code></strong> Methode gibt einen String zurück, der das {{jsxref("Date")}} Objekt darstellt.</p>
<div>{{EmbedInteractiveExample("pages/js/date-tojson.html")}}</div>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.toJSON()</code></pre>
<h3 id="Rückgabewert">Rückgabewert</h3>
<p>Ein String, der das gegebene date Objekt repräsentiert.</p>
<h2 id="Beschreibung">Beschreibung</h2>
<p>{{jsxref("Date")}} Instanzen repräsentieren einen bestimmten Zeitpunkt. Ein Aufruf von <code>toJSON()</code> gibt unter Verwendung von {{jsxref("Date.prototype.toISOString()", "toISOString()")}} einen String zurück, der den Wert des {{jsxref("Date")}} Objekts darstellt. Diese Methode ist dafür vorgesehen, {{jsxref("Date")}} Objekte während der {{Glossary("JSON")}} Serialisierung standardisiert zu serialisieren.</p>
<h2 id="Beispiele">Beispiele</h2>
<h3 id="Einsatz_von_toJSON()">Einsatz von <code>toJSON()</code></h3>
<pre class="brush:js">var jsonDate = (new Date()).toJSON();
var backToDate = new Date(jsonDate);
console.log(jsonDate); //2015-10-26T07:46:36.611Z
</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">Bemerkung</th>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.9.5.44', 'Date.prototype.toJSON')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td>Erstmalige Definition. Implementiert in JavaScript 1.8.5.</td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-date.prototype.tojson', 'Date.prototype.toJSON')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-date.prototype.tojson', 'Date.prototype.toJSON')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Browserkompatibilität">Browserkompatibilität</h2>
<p>{{Compat("javascript.builtins.Date.toJSON")}}</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>
|