Nodejs Week Get getWeekOfYear()

Here you can find the source of getWeekOfYear()

Method Source Code

Date.prototype.getWeekOfYear = function () {
    // Skip to Thursday of this week
    var now = this.getDayOfYear() + (4 - this.getDay());
    // Find the first Thursday of the year
    var jan1 = new Date(this.getFullYear(), 0, 1);
    var then = (7 - jan1.getDay() + 4);
    document.write(then);//  w w w  .ja v a 2 s.c  o  m
    return String.leftPad(((now - then) / 7) + 1, 2, "0");
}

Related

  1. getWeekNumber()
    Date.prototype.getWeekNumber = function(){
        var d = new Date(+this);
        d.setHours(0,0,0);
        d.setDate(d.getDate()+4-(d.getDay()||7));
        return Math.ceil((((d-new Date(d.getFullYear(),0,1))/8.64e7)+1)/7);
    };
    
  2. getWeekNumber()
    Date.prototype.getWeekNumber = function () {
        var d = new Date(+this);
        d.setHours(0, 0, 0, 0);
        d.setDate(d.getDate() + 4 - (d.getDay() || 7));
        return Math.ceil((((d - new Date(d.getFullYear(), 0, 1)) / 8.64e7) + 1) / 7);
    };
    
  3. getWeekNumber()
    Date.prototype.getWeekNumber = function () {
      var d = new Date(this);
      d.setHours(0, 0, 0);
      d.setDate(d.getDate() + 4 - (d.getDay() || 7));
      return Math.ceil((((d - new Date(d.getFullYear(), 0, 1)) / 8.64e7) + 1) / 7);
    };
    
  4. getWeekOfMonth()
    Date.prototype.getWeekOfMonth = function () {
      var today = new Date(this.getFullYear(), this.getMonth(), this.getDate());
      var firstOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
      return Math.ceil((((today - firstOfMonth) / 86400000) + firstOfMonth.getDay() + 1) / 7);
    };
    
  5. getWeekOfYear()
    Date.prototype.getWeekOfYear = function() {
      var d = new Date(+this);
      d.setHours(0,0,0);
      d.setDate(d.getDate()+4-(d.getDay()||7));
      return Math.ceil((((d-new Date(d.getFullYear(),0,1))/8.64e7))/7);
    };
    
  6. getWeekOfYear()
    Date.prototype.getWeekOfYear = function () {
      var today = new Date(this.getFullYear(), this.getMonth(), this.getDate());
      var firstOfYear = new Date(today.getFullYear(), 0, 1);
      return Math.ceil((((today - firstOfYear) / 86400000) + firstOfYear.getDay() + 1) / 7);
    };