如何评估年、月和日(红宝石)的日期差异? [英] How to evaluate a date difference in years, months and days (ruby)?

查看:39
本文介绍了如何评估年、月和日(红宝石)的日期差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在两个日期之间做一个简单的区分:

I have to make a simple difference between two dates:

Date.parse("2009-06-20") - Date.today

这给了我以天为单位的日期差异.

This gives me the difference of the dates in days.

任何人都知道一种可以轻松将其转换为以下格式的方法:

Anyone know a way to easily convert that to the following format:

The event occurred X years, Y months and Z days ago

谢谢.

推荐答案

在这里找到答案:

更精确的 distance_of_time_in_words

有了这颗宝石:

https://github.com/radar/dotiw

这篇关于如何评估年、月和日(红宝石)的日期差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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