Nodejs Date to Json Convert toJSON()

Here you can find the source of toJSON()

Method Source Code

Date.prototype.toJSON = function () {
  return moment(this).format().split("+")[0];
}

Related

  1. toJSON()
    Date.prototype.toJSON = function() {
        var x = new Date(this);
        x.setHours(x.getHours() - x.getTimezoneOffset() / 60);
        return x.toISOString();
    };
    
  2. toJSON()
    Date.prototype.toJSON = function() {
      return '"' + this.getUTCFullYear() + '-' +
        (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
        this.getUTCDate().toPaddedString(2) + 'T' +
        this.getUTCHours().toPaddedString(2) + ':' +
        this.getUTCMinutes().toPaddedString(2) + ':' +
        this.getUTCSeconds().toPaddedString(2) + 'Z"';
    };
    
  3. toJSON()
    Date.prototype.toJSON = function() {
      return '"' + this.getUTCFullYear() + '-' +
        (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
        this.getUTCDate().toPaddedString(2) + 'T' +
        this.getUTCHours().toPaddedString(2) + ':' +
        this.getUTCMinutes().toPaddedString(2) + ':' +
        this.getUTCSeconds().toPaddedString(2) + 'Z"';
    };
    
  4. toJSON()
    Date.prototype.toJSON = function() {
      return '"' + this.getUTCFullYear() + '-' +
        (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
        this.getUTCDate().toPaddedString(2) + 'T' +
        this.getUTCHours().toPaddedString(2) + ':' +
        this.getUTCMinutes().toPaddedString(2) + ':' +
        this.getUTCSeconds().toPaddedString(2) + 'Z"';
    };