views:

694

answers:

2

How do you format Rails timestamps in a more human-readable format? If I simply print out created_at or updated_at in my view like this:

<% @created = scenario.created_at %>

Then I will get:

2009-03-27 23:53:38 UTC

+1  A: 

This post may point you in the right direction... Lots of samples dealing with default time format, format strings, etc.

Andrew Flanagan
A: 

The strftime (from Ruby's Time) and to_formatted_s (from Rails' ActiveSupport) functions should be able to handle all of your time-formatting needs.

Greg Campbell
Thanks for that. But it seems to only work in the console and not in my Rails views.
alamodey
Can you give a fuller example of the code you're using in the view? It appears to work as expected in my view tests. Where/how are you displaying @created?
Greg Campbell