如何在Rails中添加10天的当前时间 [英] How to add 10 days to current time in Rails
本文介绍了如何在Rails中添加10天的当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过像
Time.now + 5.days
但这不行,即使我模糊地记得看到,并且非常深刻的印象,能够做一些像 2.years
等
but that doesn't work, even though I vaguely remember seeing, and being very impressed, with being able to do something like 2.years
etc.
如何在Rails 3中执行此操作?
How do I do that in Rails 3?
推荐答案
使用
Time.now + 10.days
甚至
10.days.from_now
两者都可以正常工作。你确定你在Rails,而不只是Ruby?
Both definitely work. Are you sure you're in Rails and not just Ruby?
如果你绝对在Rails,你想从哪里运行?请注意,必须加载活动支持。
If you definitely are in Rails, where are you trying to run this from? Note that Active Support has to be loaded.
这篇关于如何在Rails中添加10天的当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文