*
• day | days
• *
• weekday | weekdays
• *
• year | years
• *
• week | weeks
• *
• quarter | quarters
• *
• months | months
• *
• hour | hours
• *
• minute | minutes
• *
• second | seconds
• *
• millisecond | milliseconds
• *
* @param {Number} [amount=0] the amount to add */ add: function (/*Date*/date, /*String*/interval, /*int*/amount) { var res = addTransform(interval, date, amount || 0); amount = res[0]; var property = res[1]; var sum = new Date(+date); var fixOvershoot = res[2]; if (property) { sum["set" + property](sum["get" + property]() + amount); } if (fixOvershoot && (sum.getDate() < date.getDate())) { sum.setDate(0); } return sum; // Date }, /** * Finds the difference between two dates based on the specified interval * * @example * * var dtA, dtB; * * dtA = new Date(2005, 11, 27); * dtB = new Date(2006, 11, 27); * dateExtender.difference(dtA, dtB, "year"); //1 * * dtA = new Date(2000, 1, 29); * dtB = new Date(2001, 2, 1); * dateExtender.difference(dtA, dtB, "quarter"); //4 * dateExtender.difference(dtA, dtB, "month"); //13 * * dtA = new Date(2000, 1, 1); * dtB = new Date(2000, 1, 8); * dateExtender.difference(dtA, dtB, "week"); //1 * * dtA = new Date(2000, 1, 29); * dtB = new Date(2000, 2, 1); * dateExtender.difference(dtA, dtB, "day"); //1 * * dtA = new Date(2006, 7, 3); * dtB = new Date(2006, 7, 11); * dateExtender.difference(dtA, dtB, "weekday"); //6 * * dtA = new Date(2000, 11, 31, 23); * dtB = new Date(2001, 0, 1, 0); * dateExtender.difference(dtA, dtB, "hour"); //1 * * dtA = new Date(2000, 11, 31, 23, 59); * dtB = new Date(2001, 0, 1, 0, 0); * dateExtender.difference(dtA, dtB, "minute"); //1 * * dtA = new Date(2000, 11, 31, 23, 59, 59); * dtB = new Date(2001, 0, 1, 0, 0, 0); * dateExtender.difference(dtA, dtB, "second"); //1 * * dtA = new Date(2000, 11, 31, 23, 59, 59, 999); * dtB = new Date(2001, 0, 1, 0, 0, 0, 0); * dateExtender.difference(dtA, dtB, "millisecond"); //1 * * * @param {Date} date1 * @param {Date} [date2 = new Date()] * @param {String} [interval = "day"] the intercal to find the difference of. *
*
• day | days
• *
• weekday | weekdays
• *
• year | years
• *
• week | weeks
• *
• quarter | quarters
• *
• months | months
• *
• hour | hours
• *
• minute | minutes
• *
• second | seconds
• *
• millisecond | milliseconds
• *
*/ difference: function (/*Date*/date1, /*Date?*/date2, /*String*/interval, utc) { date2 = date2 || new Date(); interval = interval || "day"; return differenceTransform(interval, date1, date2, utc); }, /** * Formats a date to the specidifed format string * * @example * * var date = new Date(2006, 7, 11, 0, 55, 12, 345); * dateExtender.format(date, "EEEE, MMMM dd, yyyy"); //"Friday, August 11, 2006" * dateExtender.format(date, "M/dd/yy"); //"8/11/06" * dateExtender.format(date, "E"); //"6" * dateExtender.format(date, "h:m a"); //"12:55 AM" * dateExtender.format(date, 'h:m:s'); //"12:55:12" * dateExtender.format(date, 'h:m:s.SS'); //"12:55:12.35" * dateExtender.format(date, 'k:m:s.SS'); //"24:55:12.35" * dateExtender.format(date, 'H:m:s.SS'); //"0:55:12.35" * dateExtender.format(date, "ddMMyyyy"); //"11082006" * * @param date the date to format * @param {String} format the format of the date composed of the following options *
*
• G Era designator Text AD
• *
• y Year Year 1996; 96
• *
• M Month in year Month July; Jul; 07
• *
• w Week in year Number 27
• *
• W Week in month Number 2
• *
• D Day in year Number 189
• *
• d Day in month Number 10
• *
• E Day in week Text Tuesday; Tue
• *
• a Am/pm marker Text PM
• *
• H Hour in day (0-23) Number 0
• *
• k Hour in day (1-24) Number 24
• *
• K Hour in am/pm (0-11) Number 0
• *
• h Hour in am/pm (1-12) Number 12
• *
• m Minute in hour Number 30
• *
• s Second in minute Number 55
• *
• S Millisecond Number 978
• *
• z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
• *
• Z Time zone RFC 822 time zone -0800
• *