Datejs
.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();
25 Mar 2008 at 23:04
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();
30 Jul 2009 at 15:07
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.
31 Jul 2009 at 15:02
Dan: You’re welcome!