Time manipulation in ruby

后端 未结 5 797
北荒
北荒 2021-02-05 02:49

I want to create a DateTime instance that lies 20 minutes and 10 seconds in the future. I tried around with Time and DateTime in irb, but can\'t seem to figure out a way that re

5条回答
  •  悲哀的现实
    2021-02-05 03:30

    Assuming you have required Active Support or you're working in a Rails project. A very simple and readable way to do this in Ruby is:

    DateTime + 5.minutes
    Time + 5.minutes
    

    Also works with seconds, hours, days, weeks, months, years.

提交回复
热议问题