Ruby on Rails 时间加上N天

来源:互联网 发布:nginx 缓存静态文件 编辑:程序博客网 时间:2024/05/21 09:44

问题:在RoR中需要在某个时间上添加N天,或者N小时

解决方案:

自: http://stackoverflow.com/questions/4654457/how-to-add-10-days-to-current-time-in-rails

Time.now + 10.days或10.days.from_now

自:http://stackoverflow.com/questions/1356457/is-there-an-add-days-in-ruby-datetime

Date.today + n.seconds # you can use 1.secondDate.today + n.minutes # you can use 1.minuteDate.today + n.hours # you can use 1.hourDate.today + n.days # you can use 1.dayDate.today + n.weeks # you can use 1.weekDate.today + n.months # you can use 1.monthDate.today + n.years # you can use 1.year



0 0
原创粉丝点击