In Rails, display time between two dates in English

前端 未结 6 545
南方客
南方客 2020-12-07 19:15

In a Rails project I want to find the difference between two dates and then display it in natural language. Something like

>> (date1 - date2).to_natur         


        
6条回答
  •  抹茶落季
    2020-12-07 20:04

    The Rails' ActionView module includes two methods that may do what you require:

    • distance_of_time_in_words
    • distance_of_time_in_words_to_now

提交回复
热议问题