Nodejs Day of Year getDayOfYear()

Here you can find the source of getDayOfYear()

Method Source Code

/** Jan 1 is 0, etc. JS Date objects handle leap years. */
Date.prototype.getDayOfYear = function() {
   const janFirst = new Date(this.getFullYear(), 0, 0);
   const diff = this - janFirst;/*from  w  ww .j av a2 s  .c  o  m*/
   const millisPerDay = 86400000;
   // Think units: millisec div (millisec div day) = days
   return Math.floor(diff / millisPerDay);
};

Related

  1. getDOY()
    Date.prototype.getDOY = function() {
      var onejan = new Date(this.getFullYear(),0,1);
      return Math.ceil((this - onejan) / 86400000);
    
  2. getDOY()
    Date.prototype.getDOY = function(){
      var firstOfJan = new Date(this.getFullYear(),0,1);
      return Math.ceil((this - firstOfJan) / 86400000);
    
  3. getDOY()
    Date.prototype.getDOY = function() {
        var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
        var mn = this.getMonth();
        var dn = this.getDate();
        var dayOfYear = dayCount[mn] + dn;
        if (mn > 1 && this.isLeapYear()) dayOfYear++;
        return dayOfYear;
    };
    
  4. getDOY()
    ---
    ---
    Date.prototype.getDOY = function() {
      var onejan = new Date(this.getFullYear(),0,1);
      return Math.ceil((this - onejan) / 86400000);
    
  5. getDOY()
    Date.prototype.getDOY = function () {
        var onejan = new Date(this.getFullYear(), 0, 1);
        return Math.ceil((this - onejan) / 86400000) + 1;
    };
    
  6. getDayOfYear()
    Date.prototype.getDayOfYear = function () {
        var num = 0;
        Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
        for (var i = 0; i < this.getMonth(); ++i) {
            num += Date.daysInMonth[i];
        return num + this.getDate() - 1;
    
  7. getDayOfYear()
    Date.prototype.getDayOfYear = function() {
      var dayMs = 24 * 60 * 60 * 1000;
      var janFirst = new Date(this.getFullYear(),0,1);
      var date = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 2)
      return Math.ceil((date-janFirst) / dayMs);
    };