Nodejs Date Get getAge()

Here you can find the source of getAge()

Method Source Code

Date.prototype.getAge = function() {
    var today = new Date();
    var birthDate = this;
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;//w  w w  .  j ava  2 s .c o  m
    }
    return age;
}

Related

  1. compare(targetDate)
    Date.prototype.compare = function(targetDate){
      if(this.getTime() == targetDate.getTime()) return 0;
      var result = (this.getTime() > targetDate.getTime()) ? 1 : -1;
      return result;
    
  2. dateEquals(targetDate)
    Date.prototype.dateEquals = function (targetDate) {
      let sourceDate = this;
      if (targetDate instanceof Date) {
        return (sourceDate.getDate() == targetDate.getDate()) && (sourceDate.getMonth() == targetDate.getMonth()) && (sourceDate.getFullYear() == targetDate.getFullYear());
      } else {
        return false;
    };
    
  3. getAtom()
    Date.prototype.getAtom = function()
      return   this.getFullYear() + '-' + 
        this.getMonthZero() + '-' + 
        this.getDateZero() + 'T' + 
        this.getHoursZero() + ':' + 
        this.getMinutesZero() + ':' + 
        this.getSecondsZero() + 'Z';
    };
    ...
    
  4. getCode()
    Date.prototype.getCode = function(){
        var start = new Date(this.getFullYear(), 0, 0);
        var diff = this - start;
        var oneDay = 1000 * 60 * 60 * 24;
        var day = Math.floor(diff / oneDay);
        return ( 24 * day ) + this.getHours();
    };
    
  5. getDST()
    Date.prototype.getDST = function() {
        return this.getTimezoneOffset() - this.getStdTimezone();
    
  6. getDate2()
    Date.prototype.getDate2 = function () {
       var date = this.getDate();
       return (date < 10 ? '0' : '') + date;
    };