Nodejs Date ISO Format toISOString()

Here you can find the source of toISOString()

Method Source Code

Date.prototype.toISOString = Date.prototype.toISOString || function() {
  return this.getUTCFullYear() + "-"
    + ("0" + this.getUTCMonth() + 1 + "-").slice(-3)
    + ("0" + this.getUTCDate() + "T").slice(-3)
    + ("0" + this.getUTCHours() + ":").slice(-3)
    + ("0" + this.getUTCMinutes() + ":").slice(-3)
    + ("0" + this.getUTCSeconds() + ".").slice(-3)
    + ("00" + this.getUTCMilliseconds() + "Z").slice(-4);
};

if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
    "use strict";
    if (this == null) {
      throw new TypeError();//from  w  w w .  java  2  s. c  om
    }
    var t = Object(this);
    var len = t.length >>> 0;
    if (len === 0) {
      return -1;
    }
    var n = 0;
    if (arguments.length > 1) {
      n = Number(arguments[1]);
      if (n != n) { // shortcut for verifying if it's NaN
        n = 0;
      } else if (n != 0 && n != Infinity && n != -Infinity) {
        n = (n > 0 || -1) * Math.floor(Math.abs(n));
      }
    }
    if (n >= len) {
      return -1;
    }
    var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
    for (; k < len; k++) {
      if (k in t && t[k] === searchElement) {
        return k;
      }
    }
    return -1;
  }
}

Related

  1. toISOLocalString()
    Date.prototype.toISOLocalString = function() {
        if ( this.toString() === 'Invalid Date' ) {
            return this.toString();
        return new Date( this.getTime() - ( this.getTimezoneOffset() * 60 * 1000 ) ).toISOString()
            .replace( 'Z', this.getTimezoneOffsetAsTime() );
    };
    Date.prototype.getTimezoneOffsetAsTime = function() {
        var offsetMinutesTotal;
    ...
    
  2. toISOLocalString()
    Date.prototype.toISOLocalString = function() {
        var offset = {},
            pad2 = function( x ) {
                return ( x < 10 ) ? '0' + x : x;
            };
        if ( this.toString() === 'Invalid Date' ) {
            return this.toString();
        offset.minstotal = this.getTimezoneOffset();
    ...
    
  3. toISOString()
    Date.prototype.toISOString = function() {
      return this.getUTCFullYear()
        + "-" + ("0" + (this.getUTCMonth() + 1)).substr(-2, 2)
        + "-" + ("0" + this.getUTCDate()).substr(-2, 2)
        + "T" + ("0" + this.getUTCHours()).substr(-2, 2)
        + ":" + ("0" + this.getUTCMinutes()).substr(-2, 2)
        + ":" + ("0" + this.getUTCSeconds()).substr(-2, 2)
        + "Z";
    
  4. toISOString()
    Date.prototype.toISOString = function() {
      return this.getFullYear() + '-' + zpad(this.getMonth() + 1) + '-' + zpad(this.getDate()) + 'T' + zpad(this.getHours()) + ':' + zpad(this.getMinutes());
    
  5. toISOString()
    function OzeroPad(val) {
      return val < 10 ? '0' + val : '' + val;
    if(!Date.prototype.toISOString) {
      Date.prototype.toISOString = function () {
        var YYYY = this.getUTCFullYear(),
        MM = OzeroPad(this.getUTCMonth() + 1),
        DD = OzeroPad(this.getUTCDate()),
        HH = OzeroPad(this.getUTCHours()),
    ...
    
  6. toISOString(withMilliSeconds)
    function pad(number) {
      if (number < 10) {
        return '0' + number;
      return number;
    Date.prototype.toISOString = function(withMilliSeconds) {
      var ISOString = this.getUTCFullYear() +
        '-' + pad(this.getUTCMonth() + 1) +
    ...
    
  7. toISOString()
    Date.prototype.toISOString = function toISOString() {
      var date = this;
      function pad(str, len) {
        var pad = "0000";
        str = '' + str;
        return pad.substr(0, len - str.length) + str
      var y = date.getUTCFullYear(),
      m = pad(date.getUTCMonth() + 1, 2),
    ...
    
  8. toISOString()
    var global = (function () { return this; }).call(null);
    function pad(number) {
      if (number < 10) {
        return '0' + number;
      return number;
    Date.prototype.toISOString = function toISOString() {
      return this.getUTCFullYear() +
    ...
    
  9. toISOString()
    Date.prototype.toISOString = function toISOString() {
      var result, length, value;
      if (! isFinite(this)) {
        throw new RangeError();
      result = [this.getUTCFullYear(), this.getUTCMonth() + 1, this.getUTCDate(),
        this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
      length = result.length;
      while (length--) {
    ...