如何在 Rails 中将当前时间添加 10 天 [英] How to add 10 days to current time in Rails

查看:13
本文介绍了如何在 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 中,你想从哪里运行它?请注意,必须加载 Active Support.

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屋!

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