“Ago” date/time functions in Ruby/Rails

前端 未结 3 573
离开以前
离开以前 2021-01-30 19:23

I was wondering if there\'s a way in Rails to calculate time stamp like - half a minute ago, 2 minute ago, 1 day ago etc. Something like twitter real time date stamp.

I

3条回答
  •  别那么骄傲
    2021-01-30 19:48

    You can use:

    10.minutes.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.

提交回复
热议问题