Link Details

Link 2633 thumbnail
User 204938 avatar

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.
  • 5
  • 0
  • 692
  • 177

Comments

Add your comment
User 2 avatar

matt replied ago:

0 votes Vote down Vote up Reply

This is certainly one area that Java could take a few notes. Converting dates to strings is drop dead simple in Ruby.

User 204938 avatar

TDonaghe replied ago:

0 votes Vote down Vote up Reply

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!

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (5)



Voters Against This Link (0)