require time
time = Time.iso8601 Time.now.iso8601 # iso8601 <--> string
time.year # => Year of the date
time.month # => Month of the date (1 to 12)
time.day # => Day of the date (1 to 31 )
time.wday # => 0: Day of week: 0 is Sunday
time.yday # => 365: Day of year
time.hour # => 23: 24-hour clock
time.min # => 59
time.sec # => 59
time.usec # => 999999: microseconds
time.zone # => "UTC": timezone name
查阅time。 它有许多缺陷。
不幸的是,Ruby s公司的固定时间职能似乎并不通过(例如与网络相比)来很好地考虑,因此,为了其他功能,你将需要使用一些地段。
好事是,使用这些宝石同它一样,使鲁比执行成为一环。
Most useful probably is Time Calculations from ActiveSupport (Rails 3).
You don t need to require the rails but only this small library: gem install activesupport
.
然后
require active_support/all
Time.now.advance(:hours => 1) - Time.now # ~ 3600
1.hour.from_now - Time.now # ~ 3600 - same as above
Time.now.at_beginning_of_day # ~ 2010-11-24 00:00:00 +1100
# also at_beginning_of_xxx: xx in [day, month, quarter, year, week]
# same applies to at_end_of_xxx
你确实可以做很多事情,我认为你会发现什么适合你们的需要。
因此,我不向各位提供这方面的抽象例子,而是鼓励你从中试验<代码>irb,要求active_support
。
保留 实时计算。