Javascript Date getDOY()

Description

Javascript Date getDOY()


Date.prototype.getDOY = function(){
  var firstOfJan = new Date(this.getFullYear(),0,1);
  return Math.ceil((this - firstOfJan) / 86400000);
}

Javascript Date getDOY()

// Get Day of Year
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;
};

Javascript Date getDOY()

Date.prototype.getDOY = function() {
  var onejan = new Date(this.getFullYear(),0,1);
  return Math.ceil((this - onejan) / 86400000);
}



PreviousNext

Related