CNET JS Code Documentation

Native Date

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

Authors

  • Nicholas Barthelemy - https://svn.nbarthelemy.com/date-js/
  • Harald Kirshner - mail [at] digitarald.de ; http://digitarald.de
  • Aaron Newton - aaron [dot] newton [at] cnet [dot] com

License:

MIT-style license

Extra Date Parsers:

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

Examples

Date.parse('2007-06-08 16:34:52') = "Fri Jun 08 2007 09:34:52 GMT-0700 (Pacific Daylight Time)"
Date.parse('2007-06-08T16:34:52+0200') = "Fri Jun 08 2007 07:34:52 GMT-0700 (Pacific Daylight Time)"
Date.parse('today') = "Mon Dec 10 2007 11:53:25 GMT-0800 (Pacific Standard Time)"
Date.parse('tomorrow') = "Tue Dec 11 2007 11:53:25 GMT-0800 (Pacific Standard Time)"
Date.parse('yesterday') = "Sun Dec 09 2007 11:53:25 GMT-0800 (Pacific Standard Time)"
Date.parse('next monday') = "Mon Dec 17 2007 11:53:25 GMT-0800 (Pacific Standard Time)"
Date.parse('1st') = "Sat Dec 01 2007 11:53:25 GMT-0800 (Pacific Standard Time)"
Date.parse('14th October') = "Sun Oct 14 2007 11:53:25 GMT-0700 (Pacific Daylight Time)"
Date.parse('24th May, 2007') = "Thu May 24 2007 11:53:25 GMT-0700 (Pacific Daylight Time)"
Date.parse('May 3rd 2006') = "Wed May 03 2006 11:53:25 GMT-0700 (Pacific Daylight Time)"
 

See Also:

Date Method: timeAgoInWords

Syntax

date.timeAgoInWords();
 

Example

var example = new Date();
example.timeAgoInWords(); //less than a minute ago
example.decrement('hour');
example.timeAgoInWords(); //about an hour ago
 

Returns

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

Date Method: get('ordinal')

Syntax

new Date().get('ordinal');
 

Returns

  • (string) the ordinal for the day ('th', 'st', 'nd', etc).

Date Method: get('dayofyear')

Syntax

new Date().get('dayofyear');
 
  • (integer) the day of the year (i.e. for Dec. 10, you'll get 344 in a non-leap year).

Date Method: get('lastdayofmonth')

Syntax

new Date().get('lastdayofmonth');
 

Returns

  • (integer) the last day of the month (i.e. for December, you'll get 31).