Rails Rails 里个性的时间显示是怎么实现的?

hlcfan · May 06, 2012 · Last by oncity replied at May 08, 2012 · 2965 hits

rails 里个性的时间显示是怎么实现的? 比如:1 小时以前,一天以前等等。并不是只是单纯的数字. thx.

正是我想要的。感谢

不是吧。。这点东西。。那么复杂。。看看我这段,行不。

def cc_time(tar)
    t,bt = Time.at(tar),Time.now.to_i-tar
    case bt
    when 0..3600
      "#{bt / 60} 分钟前"
    when 3600..3600*24
      "#{bt / 3600} 小时前"
    when 3600*24..3600*24*2
      "昨日 #{t.strftime('%H:%M')}"
    when 3600*24*2..3600*24*7
      "#{bt / 86400} 天前"
    else
      t.strftime('%Y-%m-%d')
    end
end

You need to Sign in before reply, if you don't have an account, please Sign up first.