Set date relative to a date - Node.js Date

Node.js examples for Date:Date Calculation

Description

Set date relative to a date

Demo Code

Date.today = function() 
{
    if(this.relativeTo == null)
      return new Date().clearTime();
    else/*from w  w w .  j a  v a2  s  . co m*/
      return this.relativeTo.clone().clearTime();
}

Date.setRelativeTo = function(d) 
{
    this.relativeTo = d;
}

Date.prototype.setTimeToNow = function () 
{
    var n = Date.relativeTo || new Date();
    this.setHours(n.getHours());
    this.setMinutes(n.getMinutes());
    this.setSeconds(n.getSeconds());
    this.setMilliseconds(n.getMilliseconds());
    return this;
}

Related Tutorials