tadhg.com
tadhg.com
 

Datejs

23:57 Tue 29 Jan 2008. Updated: 23:05 25 Mar 2008
[, , ]

Date handling in JavaScript sucks. It’s quite astonishingly bad, in fact, and I always think that I’m forgetting to do something when I try to use it—but no, it appears that the major JavaScript developers have never pushed a robust date object. I’m not sure why, as the Web’s international nature seems to make that more important, not less. On top of which the browser should really tell the server what time zone it thinks it’s in, but that’s another story. Anyway, there’s a library I’ve been looking at, and which we’re apparently going to use at work, Datejs (available at datejs.com).

It doesn’t appear to have ISO 8601 support, which is a shame, but that’s hardly something that I need for my projects. I just need something that will let me parse dates relatively well, and will let me format dates without writing my own regular expressions to do so. Datejs does all that.

And it does some more, because they’ve stuck a bunch of convenience methods in there. Essentially, once I saw it had the usual bases covered, all it took to convince me that it was the library I wanted was this way to check whether today is a Wednesday:

Date.today().is().wednesday();
(next) »

3 Responses to “Datejs”

  1. geoffrey.mcgill Says:

    Thanks for the feedback!

    The latest bits from SVN (http://www.datejs.com/svn/) include support for parsing ISO 8601 date strings. Tests are available online at http://datejs.com/test/date_and_time/index.html (near bottom of page). Example

    Date.parse(“1973-01-20T23:20:50Z”);

    You can also convert a Date object into an ISO 8601 valid string using the .toISOString function. Example

    new Date().toISOString();

  2. Dan Halford Says:

    After spending hours buggering about with JavaScript’s awful native date handling (including writing my own limited date-parsing and date-to-string conversion functions) I typed ‘javascript date handling sucks’ into Google to see how many other people were similarly frustrated.
    And this post came up. And inside was the link to the Datejs library. So thank you… from the bottom of my cold rock-like heart.

  3. Tadhg Says:

    Dan: You’re welcome!

Leave a Reply