Extends the Date Type to include more powerful parsing and formatting functions; this is a further extention and depends on Date.js.

Authors

Tutorial/Demo

License

MIT-style license

Extra Date Parsers: {#Date:parsers}

In addition to the two default parsers included in Date.js, Date.Extras.js includes some additional parsers.

Examples

Date.parse('today') //"Mon Dec 10 2007 00:00:00 GMT-0800 (Pacific Standard Time)"
Date.parse('tomorrow') //"Tue Dec 11 2007 00:00:00 GMT-0800 (Pacific Standard Time)"
Date.parse('yesterday') //"Sun Dec 09 2007 00:00:00 GMT-0800 (Pacific Standard Time)"
Date.parse('next monday') //"Mon Dec 17 2007 00:00:00 GMT-0800 (Pacific Standard Time)"
Date.parse('last wednesday') //"Wed Dec 05 2007 00:00:00 GMT-0800 (Pacific Standard Time)"

See Also

Returns the difference between two dates in a compact format.

Syntax

date.timeDiff([to, separator]);

Arguments

  1. to - (date) the date to compare to; defaults to the current time.
  2. separator - (string, defaults to ':') the string used to separate the values.

Example

var example = new Date();
example.timeDiff(); //0s
example.decrement('minute');
example.timeDiff(); //1m:0s
example.decrement('hour');
example.timeDiff(); //1h:1m:0s
example.increment('hour', 2);
example.timeDiff(); //3h:1m:0s

Returns

  • (string) the compact representation of the differences in the times.

Syntax

date.timeDiffInWords([to]);

Arguments

  1. to - (date, optional) an optional date to use for the differential. Defaults to the current date/time.

Example

var example = new Date();
example.timeDiffInWords(); //less than a minute ago
example.decrement('hour');
example.timeDiffInWords(); //about an hour ago
example.increment('hour', 2);
example.timeDiffInWords(); //about an hour from now

Returns

  • (string) the friendly version of the duration since the date

Note

This method is now an alias for the old Date.timeAgoInWords.