diff options
Diffstat (limited to 'files/fr/web/javascript/reference/global_objects/date/tojson/index.html')
| -rw-r--r-- | files/fr/web/javascript/reference/global_objects/date/tojson/index.html | 81 |
1 files changed, 81 insertions, 0 deletions
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 +--- +<div>{{JSRef}}</div> + +<p>La méthode <code><strong>toJSON()</strong></code> renvoie une chaîne représentant l'objet {{jsxref("Date")}} sous forme {{Glossary("JSON")}}</p> + +<div>{{EmbedInteractiveExample("pages/js/date-tojson.html")}}</div> + +<p class="hidden">Le code source de cet exemple interactif est disponible dans un dépôt GitHub. Si vous souhaitez contribuez à ces exemples, n'hésitez pas à cloner <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> et à envoyer une <em>pull request</em> !</p> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="syntaxbox"><var>dateObj</var>.toJSON()</pre> + +<h3 id="Valeur_de_retour">Valeur de retour</h3> + +<p>Une chaîne de caractères représentant la date indiquée.</p> + +<h2 id="Description">Description</h2> + +<p>Les instances de {{jsxref("Date")}} identifient un instant précis dans le temps. Appeler <code>toJSON()</code> 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 <code>Date</code>. Cette méthode est généralement utilisée, par défaut, pour sérialiser les objets <code>Date</code> lors d'une sérialisation au format JSON.</p> + +<h2 id="Exemple">Exemple</h2> + +<h3 id="Utiliser_toJSON()">Utiliser <code>toJSON()</code></h3> + +<pre class="brush:js">var jsonDate = (new Date()).toJSON(); +var retourVersDate = new Date(jsonDate); + +console.log(jsonDate); //2015-10-26T07:46:36.611Z +</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">État</th> + <th scope="col">Commentaires</th> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.9.5.44', 'Date.prototype.toJSON')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td>Définition initiale. Implémentée avec 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="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> + +<p class="hidden">Le tableau de compatibilité de cette page a été généré à partir de données structurées. Si vous souhaitez contribuer à ces données, n'hésitez pas à envoyer une <em>pull request</em> sur <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a>.</p> + +<p>{{Compat("javascript.builtins.Date.toJSON")}}</p> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li>{{jsxref("Date.prototype.toLocaleDateString()")}}</li> + <li>{{jsxref("Date.prototype.toTimeString()")}}</li> + <li>{{jsxref("Date.prototype.toUTCString()")}}</li> +</ul> |
