计算两个日期之间的天数 [英] Count number of days between two dates

查看:78
本文介绍了计算两个日期之间的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算这两个日期之间的天数?

How do I count the number of days between these two dates?

start_date = Date.parse "2012-03-02 14:46:21 +0100"
end_date =  Date.parse "2012-04-02 14:46:21 +0200"

推荐答案

使用 Date(和 DateTime)类,您可以执行 (end_date - start_date).to_i 来获得天数差异.

With the Date (and DateTime) classes you can do (end_date - start_date).to_i to get the number of days difference.

这篇关于计算两个日期之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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