Node.js examples for Date:Date Calculation
Javascript date add and diff
// from http://trentrichardson.com/2011/09/27/better-javascript-date-add-and-diff/ Date.prototype.adjust = function (part, amount) { part = part.toLowerCase();// w w w . ja v a 2s . c o m var map = { years:'FullYear', months:'Month', weeks:'Hours', days:'Hours', hours:'Hours', minutes:'Minutes', seconds:'Seconds', milliseconds:'Milliseconds', utcyears:'UTCFullYear', utcmonths:'UTCMonth', utcweeks:'UTCHours', utcdays:'UTCHours', utchours:'UTCHours', utcminutes:'UTCMinutes', utcseconds:'UTCSeconds', utcmilliseconds:'UTCMilliseconds' }; var mapPart = map[part]; if (part == 'weeks' || part == 'utcweeks') amount *= 168; if (part == 'days' || part == 'utcdays') amount *= 24; this['set' + mapPart](this['get' + mapPart]() + amount); return this; };