Get beginning/end of day, beginning/end of month - Node.js Date

Node.js examples for Date:Month

Description

Get beginning/end of day, beginning/end of month

Demo Code

;Date.prototype.$beginningOfDay = function() {
  return new Date(this.getFullYear(), this.getMonth(), this.getDate());
};

Date.prototype.$endOfDay = function() {
  return new Date(this.getFullYear(), this.getMonth(), this.getDate(), 23, 59, 59, 999);
};

Date.prototype.$beginningOfMonth = function() {
  return new Date(this.getFullYear(), this.getMonth());
};

Date.prototype.$endOfMonth = function() {
  return new Date(this.getFullYear(), this.getMonth() + 1, 0, 23, 59, 59, 999);
};

Date.prototype.$monthName = function() {
  var names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  return names[this.getMonth()];
};

Related Tutorials