のぶLab.

流しのソフトウェアエンジニアの雑記帳. Android, Scala, Clojure, Ruby on Railsなど

日付・時刻の操作

現在時刻取得
DateTime.now
日時指定
DateTime.new(year, month, day, hour, min)
パラメータ取得
now = DateTime.now
now.year
now.month
now.day
now.hour
now.min
加算した値を返却
now = DateTime.now
now >> 1 # 1ヶ月後
now + 1 # 1日後# 大小比較now = DateTime.now
futue = now >> 2
now <= future # true

参考
逆引きRuby - 日付と時刻
http://www.namaraii.com/rubytips/?%E6%97%A5%E4%BB%98%E3%81%A8%E6%99%82%E5%88%BB
DateTime に月、日、時、分、秒を足す。 - こせきの技術日記
http://koseki.hatenablog.com/entry/20080527/date