パンくず
Ruby Cookbook
日付、日時の加算
概要
日付、日時の加算
サンプル
# encoding: Windows-31J require 'date' today = Date.today puts today puts today + 1 # => todayに1日足した結果 puts today - 1 # => todayから1日引いた結果 puts today >> 1 # => todayに1ヶ月足した結果 puts today << 1 # => todayから1ヶ月引いた結果 now = Time.now puts now puts now + 1 # => nowに1秒足した結果 puts now - 1 # => nowに1秒引いた結果
出力
2012-06-24 2012-06-25 2012-06-23 2012-07-24 2012-05-24 2012-06-24 23:07:08 +0900 2012-06-24 23:07:09 +0900 2012-06-24 23:07:07 +0900