Javascript Date toISOString() method

Description

Javascript Date toISOString() method


Date.prototype.toISOString = function toISOString() {
  var date = this;

  return ((date.getUTCMonth() + 1) / 100 + date.toUTCString() + date / 1e3).replace(/..(..).+?(\d+)\D+(\d+).(\S+).*(...)/,'$3-$1-$2T$4.$5Z');
};

Javascript Date toISOString()

// Date.prototype.toISOString
Date.prototype.toISOString = function toISOString() {
 var date = this;

 return ((date.getUTCMonth() + 1) / 100 + date.toUTCString() + date / 1e3).replace(/..(..).+?(\d+)\D+(\d+).(\S+).*(...)/,'$3-$1-$2T$4.$5Z');
};

Javascript Date toISOString()

Date.prototype.toISOString
    || function() {
      function e(e) {
        return e < 10 ? "0" + e : e
      }//from ww w.jav a 2 s . c  o m
      Date.prototype.toISOString = function() {
        return this.getUTCFullYear()
            + "-"
            + e(this.getUTCMonth() + 1)
            + "-"
            + e(this.getUTCDate())
            + "T"
            + e(this.getUTCHours())
            + ":"
            + e(this.getUTCMinutes())
            + ":"
            + e(this.getUTCSeconds())
            + "."
            + (this.getUTCMilliseconds() / 1e3).toFixed(3).slice(2,
                5) + "Z"
      }
    }();

Javascript Date toISOString()

// Copyright (C) Nik Silver 2010.
// See licence.txt for terms and conditions not explicitly stated elsewhere.

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";/*  w w  w. ja  v  a2 s .com*/
}

Javascript Date 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),/*from  w ww .ja v a 2 s  .com*/
 d = pad(date.getUTCDate(), 2),
 h = pad(date.getUTCHours(), 2),
 i = pad(date.getUTCMinutes(), 2),
 s = pad(date.getUTCSeconds(), 2),
 ms = pad(date.getUTCMilliseconds(), 3);

 return y +'-'+ m +'-'+ d + 'T' + h +':'+ i +':'+ s +'.'+ ms +'Z';
};

Javascript Date toISOString()

'use strict';/*from  ww w  .  ja  v a  2 s  .c  o m*/

(function () {

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() +
    '-' + 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';
};

Date.prototype.toJSON = function toJSON() {
  return Date.prototype.toISOString.call(this);
};

})();

Javascript Date toISOString()

/**/*ww  w.  j  a  va2s.c o  m*/
 * Date.prototype.toISOString Polyfill
 *
 * This function taken with minor changes from https://github.com/kriskowal/es5-shim
 */

Date.prototype.toISOString = function toISOString() {
 var result, length, value;
 if (! isFinite(this)) {
  throw new RangeError();
 }

 // the date time string format is specified in 15.9.1.15.
 result = [this.getUTCFullYear(), this.getUTCMonth() + 1, this.getUTCDate(),
  this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];

 length = result.length;
 while (length--) {
  value = result[length];
  // pad months, days, hours, minutes, and seconds to have two digits.
  if (value < 10) {
   result[length] = '0' + value;
  }
 }
 // pad milliseconds to have three digits.
 return result.slice(0, 3).join('-') + 'T' + result.slice(3).join(':') + '.' +
  ('000' + this.getUTCMilliseconds()).slice(-3) + 'Z';
};

/* End of file toisostring.js */



PreviousNext

Related