views:

190

answers:

1

Hi - I was wondering, if theres a way in rails to calculate time stamp like - half a minute ago, 2 minute ago, 1 day ego etc. Something like twitter real time date stamp.

I want to know if ruby/rails has a pre-built function for such date-time conversion??

+7  A: 

Rails has a number of methods for date and time

You can use a number of methods on the object itself, such as:

10.mins.ago
2.days.since

Or in your views you have the helpers:

distance_of_time_in_words(from_time, to_time)
time_ago_in_words(from_time)

Check the API for details and more options: http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M002261

Toby Hede