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();

now.format(“m/dd/yy”);
// Returns, e.g., 6/09/07

// You can use one of several named masks
now.format(“isoDateTime”);
// 2007-06-09T17:46:21

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

534 thoughts on “Javascript, Dates, Times, and One Man’s Dream”

  1. Delicious for the next 30 years. Of course, I wouldn’t mind getting some Y2K-style paychecks in about 30 years when everyone goes “I can’t believe we’re still running code from 2010!!” 😀

Leave a Reply