Calculate difference in days ActiveSupport:TimeWithZone in the most “rubyish” style?

后端 未结 3 1639
无人共我
无人共我 2020-12-23 16:50

I have a feeling someone is going to point me to another question that answers this but I\'ve been searching with no luck over this simple issue.

I have a Activereco

3条回答
  •  無奈伤痛
    2020-12-23 16:59

    Rails actually has a method built in for just this sort of thing.

    checkout #time_ago_in_words

    So, for the original case...

    ((Time.zone.now - myActiveRecord.visit_date)/86400).to_i

    vs

    time_ago_in_words(myActiveRecord.visit_date)

提交回复
热议问题