Serialization function for Date datatype - Node.js Date

Node.js examples for Date:Serialization

Description

Serialization function for Date datatype

Demo Code


/**/*  w  w  w  .java  2 s .  com*/
 *  Serialization function for Date datatype.
 */
Date.prototype.serialize = function()
{
    return '<dateTime.iso8601>' +
           this.getFullYear() +
           ( this.getMonth() < 10 ? '0' : '' ) + this.getMonth() +
           ( this.getDay() < 10 ? '0' : '' ) + this.getDay() + 'T' +
           ( this.getHours() < 10 ? '0' : '' ) + this.getHours() + ':' +
           ( this.getMinutes() < 10 ? '0' : '' ) + this.getMinutes() + ':' +
           ( this.getMinutes() < 10 ? '0' : '' ) + this.getSeconds() + 
           '</dateTime.iso8601>'; // Phew :-)
}

Related Tutorials