require 'time' time = Time.iso8601 Time.now.iso8601
Take a look at Time . It has a lot of things.
Unfortunately, the built-in functions of Date-Time Ruby do not seem to be thought out (compared to .NET, for example), so for other functions you will need to use some gems.
Itβs good that using these gems really looks like a Ruby built-in implementation.
Most useful may be Time Calculation from ActiveSupport (Rails 3).
You do not need to require rails, but only this small library: gem install activesupport .
Then you can do :
require 'active_support/all' Time.now.advance(:hours => 1) - Time.now
There are many things you can do, and I believe that you will find something that best suits your needs.
Therefore, instead of giving you abstract examples, I recommend that you experiment with irb , requiring irb from it.
Keep your time calculations handy.
source share