Format Date value to ISO String - Node.js String

Node.js examples for String:Format

Description

Format Date value to ISO String

Demo Code

if (!Date.prototype.toISOString) {
    Date.prototype.toISOString = function() {
        function pad(n) { return n < 10 ? '0' + n : n }
        return this.getUTCFullYear() + '-'
            + pad(this.getUTCMonth() + 1) + '-'
            + pad(this.getUTCDate()) + 'T'
            + pad(this.getUTCHours()) + ':'
            + pad(this.getUTCMinutes()) + ':'
            + pad(this.getUTCSeconds()) + '.'
            + pad(this.getUTCMilliseconds()) + 'Z';
    };//from w ww . j av  a  2s.c om
}

Related Tutorials