By TDonaghe
via rubynoob.com
Published: Sep 01 2006 / 01:46
It's not obvious how to do friendly date formatting in Ruby. At least it wasn't easy for me to figure out. I didn't find too many other places on the net that described how to turn Time.now into something like "12/13/08" or "Monday September 16, 2005." I found the answer buried in the ruby api docs and wrote this tutorial for anyone else like me who's been looking in vain.
Comments
matt replied ago:
This is certainly one area that Java could take a few notes. Converting dates to strings is drop dead simple in Ruby.
TDonaghe replied ago:
Simple, for sure. Obvious? Heck no. I'm embarassed to write something that looks like: Time.now.strftime("%A %B %d, %Y") in ruby. That is some UGLY code. But, being ruby I suppose that I can always make my own method on the Time class and format it however I want. It's just those %A's and %I's are so freaking ugly!
Voters For This Link (5)
Voters Against This Link (0)