“过去” Ruby / Rails中的日期/时间函数 [英] "Ago" date/time functions in Ruby/Rails

查看:138
本文介绍了“过去” Ruby / Rails中的日期/时间函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果Rails有一种方法来计算时间戳,就像半分钟前,2分钟前,1天前等等。像Twitter的实时日期戳。

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.

我想知道Ruby / Rails是否具有这样的日期时间转换的内置函数?

I want to know if Ruby/Rails has a built-in function for such date-time conversion?

推荐答案

您可以使用:

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)

有关详细信息和更多选项,请 API

Check the API for details and more options.

这篇关于“过去” Ruby / Rails中的日期/时间函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆