From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../global_objects/date/tojson/index.html | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/date/tojson/index.html (limited to 'files/fr/web/javascript/reference/global_objects/date/tojson') diff --git a/files/fr/web/javascript/reference/global_objects/date/tojson/index.html b/files/fr/web/javascript/reference/global_objects/date/tojson/index.html new file mode 100644 index 0000000000..0f2b0c7bc7 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/date/tojson/index.html @@ -0,0 +1,81 @@ +--- +title: Date.prototype.toJSON() +slug: Web/JavaScript/Reference/Objets_globaux/Date/toJSON +tags: + - Date + - JavaScript + - Méthode + - Prototype + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Date/toJSON +--- +
{{JSRef}}
+ +

La méthode toJSON() renvoie une chaîne représentant l'objet {{jsxref("Date")}} sous forme {{Glossary("JSON")}}

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

Syntaxe

+ +
dateObj.toJSON()
+ +

Valeur de retour

+ +

Une chaîne de caractères représentant la date indiquée.

+ +

Description

+ +

Les instances de {{jsxref("Date")}} identifient un instant précis dans le temps. Appeler toJSON() renvoie une chaîne de caractères formatée en JSON (en utilisant {{jsxref("Date.prototype.toISOString", "toISOString()")}}), représentant la valeur de l'objet Date. Cette méthode est généralement utilisée, par défaut, pour sérialiser les objets Date lors d'une sérialisation au format JSON.

+ +

Exemple

+ +

Utiliser toJSON()

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

Spécifications

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES5.1', '#sec-15.9.5.44', 'Date.prototype.toJSON')}}{{Spec2('ES5.1')}}Définition initiale. Implémentée avec JavaScript 1.8.5.
{{SpecName('ES6', '#sec-date.prototype.tojson', 'Date.prototype.toJSON')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-date.prototype.tojson', 'Date.prototype.toJSON')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ + + +

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

+ +

Voir aussi

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