How do you do relative time in Rails?

前端 未结 11 1538
借酒劲吻你
借酒劲吻你 2020-12-02 03:43

I\'m writing a Rails application, but can\'t seem to find how to do relative time, i.e. if given a certain Time class, it can calculate \"30 seconds ago\" or \"2 days ago\"

11条回答
  •  無奈伤痛
    2020-12-02 04:40

    You can use the arithmetic operators to do relative time.

    Time.now - 2.days 
    

    Will give you 2 days ago.

提交回复
热议问题