Connect with me
Search
Twitter Feed
Navigation
« Cross Browser Copy and Paste - with ZeroClipboard *updated* | Main | jQuery 1.3 - Case Insensitive :contains() »
Thursday
Apr162009

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

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.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>