A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString below:

Date.prototype.toISOString() - JavaScript | MDN

Date.prototype.toISOString()

Baseline Widely available

La méthode toISOString() renvoie une chaîne de caractères au format ISO (ISO 8601 Extended Format), qui peut être décrite de cette façon : YYYY-MM-DDTHH:mm:ss.sssZ (toujours longue de 24 caractères) ou de cette façon ±YYYYYY-MM-DDTHH:mm:ss.sssZ (27 caractères). Le fuseau horaire est toujours UTC, comme l'indique le suffixe « Z » (pour zéro décalage avec UTC).

Exemple interactif
const event = new Date("05 October 2011 14:48 UTC");
console.log(event.toString());
// Expected output: "Wed Oct 05 2011 16:48:00 GMT+0200 (CEST)"
// Note: your timezone may vary

console.log(event.toISOString());
// Expected output: "2011-10-05T14:48:00.000Z"
Syntaxe Valeur de retour

Une chaîne de caractères représentant la date indiquée au format ISO 8601 selon le temps universel.

Exemples Utiliser toISOString()
var aujourdhui = new Date("05 October 2011 14:48 UTC");

console.log(aujourdhui.toISOString()); // Renvoie "2011-10-05T14:48:00.000Z"

L'exemple ci-dessus analyse une chaîne de caractères non-standard, qui peut donc être incorrectement intérprété par des navigateurs n'utilisant pas Gecko.

Prothèse d'émulation (polyfill)

Cette méthode fut standardisée avec la cinquième édition d'ECMAScript. Afin d'utiliser cette méthode avec les moteurs qui n'en disposent pas nativement, on pourra utiliser ce fragment de code :

if (!Date.prototype.toISOString) {
  (function () {
    function pad(number) {
      if (number < 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"
      );
    };
  })();
}
Spécifications Compatibilité des navigateurs Voir aussi

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4