Tuesday, July 29, 2008

Time for protodate


I decided to stay up late and implement Ruby's Time.strftime in Javascript. Prototype's Template class ended up making this easy to implement. To clarify, here is how you might use this function.


1 new Date().format("Printed on %m/%d/%Y at %I:%M%p")
2 => "Printed on 07/29/2008 at 12:31AM"


I checked my code into github, so take at your own peril. (http://github.com/matthuhiggins/protodate/tree/master)

And yes, I know that this has already been blogged about at alternateidea. However, that particular solution converts all values to UTC, whereas I almost always want to use the browser's local time zone when prettying up dates.

0 comments: