datejs - the javascript date library that will let you work with dates like a ninja

Some thoughts scribbled down on Thursday 16 April 2009 at 07:50 AM

Dates in Javascript have always been a bit of a pain to work with because of the very limited API. Take this for example:

Parsing a date string and adding a week

var d = new Date(Date.parse("15/04/2009"));
d = d.setDate(d.getDate() + 7);

The above code is painful and unintuitive.

Enter DateJS

The above can be written like:

var d = Date.parse("15/04/2009").next().week();

Or..

var d = Date.parse("15/04/2009").add(1).week();

Basically it simplifies working with dates on the client site and the feature I found most useful was being about to tell what day of the week it is:

var isWednesday = Date.parse("15/04/2009").is().Wednesday();

Be sure to checkout this useful javascript library.

Comments

There are currently no comments.

Post your comment