ROR + Ruby Date 减少 15 分钟
如果我有 @time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
,
如何将此时间减少 15 分钟?
我已经尝试过这个 :: @reducetime = @time-15.mins
,在控制台上工作正常,但在执行时出错。除此之外还有什么办法可以解决这个问题。
谢谢
If I have @time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
,
How can I reduce this time by 15 minutes ?
I already tried this one :: @reducetime = @time-15.minutes
, works fine at console but give errors while execution. Other than this Is there any way to resolve this issue.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是您在将时间视为时间之前将其格式化为字符串。这会更有意义:
在准备好显示数据之前,您不应该格式化数据。
如果您必须将
@time
作为格式化时间,那么您必须在计算@reducetime
之前解析它:Your problem is that you're formatting your time into a string before you're done treating it as a time. This would make more sense:
You shouldn't format your data until right before you're ready to display it.
If you must have
@time
as the formatted time then you're going to have to parse it before computing@reducetime
: