Nodejs Date ISO Format rfc3339()

Here you can find the source of rfc3339()

Method Source Code

function f(n) {/*from   w ww . j av  a  2  s.com*/
    return n < 10 ? '0' + n : n;
}

Date.prototype.rfc3339 = function() {
    return this.getUTCFullYear()   + '-' +
         f(this.getUTCMonth() + 1) + '-' +
         f(this.getUTCDate())      + 'T' +
         f(this.getUTCHours())     + ':' +
         f(this.getUTCMinutes())   + ':' +
         f(this.getUTCSeconds())   + 'Z';
};

Related

  1. getISOWeek()
    Date.prototype.getISOWeek = function () {
      var target = new Date(this.valueOf());
      var dayNr = (this.getDay() + 6) % 7;
      target.setDate(target.getDate() - dayNr + 3);
      var firstThursday = target.valueOf();
      target.setMonth(0, 1);
      if (target.getDay() != 4) {
        target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
      return 1 + Math.ceil((firstThursday - target) / 604800000);
    
  2. getISOYear()
    Date.prototype.getISOYear = function () {
      var target  = new Date(this.valueOf());
      target.setDate(target.getDate() - ((this.getDay() + 6) % 7) + 3);
      return target.getFullYear();
    
  3. iso8601()
    Date.prototype.iso8601 = function () {
        return this.getUTCFullYear() + '-' +
            (this.getUTCMonth() + 1).zfill(2) + '-' +
            this.getUTCDate().zfill(2) + 'T' +
            this.getUTCHours().zfill(2) + ':' +
            this.getUTCMinutes().zfill(2) + ':' +
            this.getUTCSeconds().zfill(2) + '.' +
            this.getUTCMilliseconds().zfill(3);
    };
    ...
    
  4. isoDate()
    Date.prototype.isoDate = function() {
      return this.getFullYear() + "-" + (parseInt(this.getMonth())+1) + "-" + this.getDate();
    
  5. isoDate()
    Date.prototype.isoDate = function(){
      var d = this;
      return d.year();
    function toJSArray(arr) {
      var len = [arr count],
          res = [];
      while(len--){
        res.push(arr[len]);
    ...
    
  6. rfc3339()
    function f(n) { 
        return n < 10 ? '0' + n : n;
    Date.prototype.rfc3339 = function() {
        return this.getUTCFullYear() + '-' +
             f(this.getUTCMonth() + 1) + '-' +
             f(this.getUTCDate()) + 'T' +
             f(this.getUTCHours()) + ':' +
             f(this.getUTCMinutes()) + ':' +
    ...
    
  7. rfc3339()
    function f(n) {    
        return n < 10 ? '0' + n : n;
    Date.prototype.rfc3339 = function() {
        return this.getUTCFullYear()   + '-' +
             f(this.getUTCMonth() + 1) + '-' +
             f(this.getUTCDate())      + 'T' +
             f(this.getUTCHours())     + ':' +
             f(this.getUTCMinutes())   + ':' +
    ...
    
  8. rfc822date()
    "use strict";
    Date.prototype.rfc822date = function() {
        var weekday_name = { 0:'Sun', 1:'Mon', 2:'Tue', 3:'Wed', 4:'Thu', 5:'Fri', 6: 'Sat' };
        var month_name = { 0:'Jan', 1:'Feb', 2:'Mar', 3:'Apr', 4:'May', 5:'Jun', 6: 'Jul', 7:'Aug', 8:'Sep', 9:'Oct', 10:'Nov', 11:'Dec' };
        var zeropad = function(num, length) {
            if ( length === undefined ) {
                length = 2;
            var add = length - num.toString().length;
    ...
    
  9. toISO8601String(format, offset)
    Date.prototype.toISO8601String = function (format, offset) {
        if (!format) { var format = 6; }
        if (!offset) {
            var offset = 'Z';
            var date = this;
        } else {
            var d = offset.match(/([-+])([0-9]{2}):([0-9]{2})/);
            var offsetnum = (Number(d[2]) * 60) + Number(d[3]);
            offsetnum *= ((d[1] == '-') ? -1 : 1);
    ...