Get Week from Date - Node.js Date

Node.js examples for Date:Week

Description

Get Week from Date

Demo Code

Date.prototype.getWeek = function() {
  var onejan = new Date(this.getFullYear(),0,1);
  return Math.ceil((((this - onejan) / 86400000) + onejan.getDay())/7);
} 
Date.prototype.getWeekMonday = function() {
  var res = new Date();
  (this.getDay() == 0) ? res.setTime(this.getTime() - (6 * 86400000)) : res.setTime(this.getTime() + 86400000 - (this.getDay() * 86400000));
  return res;/*from   w w  w.j  a  v  a2 s . com*/
} 
  
Date.prototype.getWeekSunday = function() {
  res = this.getWeekMonday()
  res.setTime(res.getTime() + 6*86400000);
  return res;
}   

Date.prototype.fromString = function(myString) {
  var parts = myString.split(/[- :]/);
  this.setFullYear(parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, parseInt(parts[2], 10));  
  // this.setFullYear(parts[0]);  
  // this.setMonth(parts[1] - 1);  
  // this.setDate(parts[2]);  
}

Related Tutorials