Javascript, Dates, Times, and One Man’s Dream

OK, so the title of this post might be a bit overstating.

But, if you work with Javascript and need to use dates/times, you should absolutely check out a JS library for formatted dates and times by Steven Levithan (who is obviously cool; his blog is titled “Flagrant Badassery”).

It’s a library that extends the stock Date object in Javascript to let you easily generate nicely formatted dates. Just put the code in a file and load it up. Then you can do neat things like this (adapted from his blog)

var now = new Date();

// Returns, e.g., 6/09/07

// You can use one of several named masks
// 2007-06-09T17:46:21

// …Or add your own
dateFormat.masks.hammerTime = ‘HH:MM! “Can\’t touch this!”‘;
// 17:46! Can’t touch this!