Die toJSON()
Methode gibt einen String zurück, der das Date
Objekt darstellt.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Syntax
dateObj.toJSON()
Rückgabewert
Ein String, der das gegebene date Objekt repräsentiert.
Beschreibung
Date
Instanzen repräsentieren einen bestimmten Zeitpunkt. Ein Aufruf von toJSON()
gibt unter Verwendung von toISOString()
einen String zurück, der den Wert des Date
Objekts darstellt. Diese Methode ist dafür vorgesehen, Date
Objekte während der JSON Serialisierung standardisiert zu serialisieren.
Beispiele
Einsatz von toJSON()
var jsonDate = (new Date()).toJSON();
var backToDate = new Date(jsonDate);
console.log(jsonDate); //2015-10-26T07:46:36.611Z
Spezifikationen
Spezifikation | Status | Bemerkung |
---|---|---|
ECMAScript 5.1 (ECMA-262) Die Definition von 'Date.prototype.toJSON' in dieser Spezifikation. |
Standard | Erstmalige Definition. Implementiert in JavaScript 1.8.5. |
ECMAScript 2015 (6th Edition, ECMA-262) Die Definition von 'Date.prototype.toJSON' in dieser Spezifikation. |
Standard | |
ECMAScript (ECMA-262) Die Definition von 'Date.prototype.toJSON' in dieser Spezifikation. |
Lebender Standard |
Browserkompatibilität
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.