3 Oct 2009, 2:16pm
Ruby on Rails: datetime helpers time time ago in words
by bseanvt

leave a comment
Ruby on Rails: datetime helpers time time ago in words
by bseanvt
leave a comment
Date and Time Helpers in Rails
Just for reference http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M001695
This post was created about <%= time_ago_in_words @post.created_at %> ago
Custom Date Formats for Your Rails Application
If you use a consistent date format often in your Rails applciation, it is worth it to add the format to your application environment. You can do this by adding it to the bottom of the config/environment.rb file.
Time::DATE_FORMATS[:my_custom_format] = "%A %B %d, %Y"
Now you can use it in your views like this
@post.created_at.to_s(:my_custom_format)
Which will output something like Monday May 5, 2009


