红宝石日期减法
我在 Ruby 中遇到日期减法问题,
"2011-03-29".to_date - "2011-03-20".to_date #=> (9/1)
("2011-03-29".to_date - "2011-03-20".to_date).to_i #=> 9
似乎它返回日期之间的天数差异。
日期差的年数、月数、天数,
ie ("2011-03-29".to_date - "2011-03-20".to_date)
现在我的问题是返回
0 years, 0 month and 9 days
谢谢。
I have a problem with date subtraction in Ruby
"2011-03-29".to_date - "2011-03-20".to_date #=> (9/1)
("2011-03-29".to_date - "2011-03-20".to_date).to_i #=> 9
Seems it's returning the difference between dates in number of days.
Now my problem is to return number of years, months, days of the date difference
ie ("2011-03-29".to_date - "2011-03-20".to_date)
should return
0 years, 0 month and 9 days
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试此链接:
http://api. rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words
或
参考:在 Rails 中,用英语显示两个日期之间的时间
You can try this link:
http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words
OR
Reference: In Rails, display time between two dates in English
我知道它有点脏,但你尝试过吗:
I know it is kinda dirty but have you tried: