Undocumented strftime directive
So, you’ve got to display a clearly readable datetime. You might put something like this in your environment.rb file:
[Time::DATE_FORMATS].each{ |format| format.update(:slashes_with_time => ‘%m/%d/%Y %I:%M %p’) }
That works, but it produces an hour with leading zeroes, which is a little less readable for most people. When you search through the docs for strftime, you might think you’ll need to resort to String manipulation to get rid of the leading zero. But there’s a nice AFAICT undocumented strftime directive that’ll do the trick for you: %l (lowercase L).
[Time::DATE_FORMATS].each{ |format| format.update(:slashes_with_time => ‘%m/%d/%Y %l:%M %p’) }
Now, you just use it like this:
my_datetime.to_s(:slashes_with_time)
=> “10/15/2007 3:48 PM”
There’s an extra space there between the date and time, but I can live with that.