Tim on September 16th, 2008

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!

4 Responses to “Javascript, Dates, Times, and One Man’s Dream”

  1. Yes, but can it do cool things like python?

    datetime.today()+datetime.timedelta(weeks=-1) # 1 week ago

  2. Nope. Still the dark ages of Unix timestamps. But, if you have to use Unix timestamps, you may as well put a nice wrapper around it.

  3. dark ages of Unix timestamps? please. more like wonderfully persistent and delicious ages of Unix timestamps.

  4. 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!!” :D

Trackbacks/Pingbacks

Leave a Reply

You will be able to edit your comment after submitting.