概要
time
詳細
time について
time
数値を元にして日時を扱う。
サンプル
# encoding: utf-8 require 'active_support/core_ext' require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS 1.second.from_now 1.minutes.from_now 1.hours.from_now 1.days.from_now 1.week.from_now 1.weeks.from_now 1.fortnights.from_now 1.months.from_now 1.years.from_now 1.years.since 1.years.ago 1.years.until 1.years.until(Time.local(2014, 1, 1)) EOS __END__ ・下記はTbpgrUtils gemの機能 bulk_puts_eval https://rubygems.org/gems/tbpgr_utils https://github.com/tbpgr/tbpgr_utils
出力
1.second.from_now # => 2014-03-06 21:22:18 +0900 1.minutes.from_now # => 2014-03-06 21:23:17 +0900 1.hours.from_now # => 2014-03-06 11:22:17 +0900 1.days.from_now # => 2014-03-07 21:22:17 +0900 1.week.from_now # => 2014-03-13 21:22:17 +0900 1.weeks.from_now # => 2014-03-13 21:22:17 +0900 1.fortnights.from_now # => 2014-03-20 21:22:17 +0900 1.months.from_now # => 2014-04-06 21:22:17 +0900 1.years.from_now # => 2015-03-06 21:22:17 +0900 1.years.since # => 2015-03-06 21:22:17 +0900 1.years.ago # => 2013-03-06 21:22:17 +0900 1.years.until # => 2013-03-06 21:22:17 +0900 1.years.until(Time.local(2014, 1, 1)) # => 2013-01-01 00:00:00 +0900