Format date as rfc 3339 - Node.js Date

Node.js examples for Date:Date Format

Description

Format date as rfc 3339

Demo Code


function f(n) {/*from   ww w.java  2 s  . c om*/
    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 Tutorials