class TimeWithZone
Ruby on Rails 6.1.7.10
Since v2.2.3A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are limited to UTC and the system’s ENV['TZ'] zone.
You shouldn’t ever need to create a TimeWithZone instance directly via new. Instead use methods local, parse, at and now on TimeZone instances, and in_time_zone on Time and DateTime instances.
Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)' Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00 Time.zone.parse('2007-02-10 15:30:45') # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00 Time.zone.at(1171139445) # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00 Time.zone.now # => Sun, 18 May 2008 13:07:55.754107581 EDT -04:00 Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
See Time and TimeZone for further documentation of these methods.
TimeWithZone instances implement the same API as Ruby Time instances, so that Time and TimeWithZone instances are interchangeable.
t = Time.zone.now # => Sun, 18 May 2008 13:27:25.031505668 EDT -04:00 t.hour # => 13 t.dst? # => true t.utc_offset # => -14400 t.zone # => "EDT" t.to_s(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400" t + 1.day # => Mon, 19 May 2008 13:27:25.031505668 EDT -04:00 t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00.000000000 EST -05:00 t > Time.utc(1999) # => true t.is_a?(Time) # => true t.is_a?(ActiveSupport::TimeWithZone) # => true
Inherits from
Constants
Attributes
Methods (defined here)
- # +
- # -
- # <=>
- # acts_like_time?
- # advance
- # ago
- # as_json
- # between?
- # blank?
- # change
- # comparable_time
- # dst?
- # eql?
- # formatted_offset
- # freeze
- # future?
- # getgm
- # getlocal
- # getutc
- # gmt?
- # gmtime
- # gmtoff
- # gmt_offset
- # hash
- # httpdate
- # in
- # inspect
- # in_time_zone
- # is_a?
- # isdst
- # iso8601
- # kind_of?
- # localtime
- # marshal_dump
- # marshal_load
- # method_missing
- # next_day?
- # past?
- # period
- # prev_day?
- # respond_to?
- # respond_to_missing?
- # rfc2822
- # rfc3339
- # rfc822
- # since
- # strftime
- # time
- # to_a
- # to_datetime
- # today?
- # to_f
- # to_formatted_s
- # to_i
- # tomorrow?
- # to_r
- # to_s
- # to_time
- # tv_sec
- # utc
- # utc?
- # utc_offset
- # xmlschema
- # yesterday?
- # zone
- self. name
- self. new
Private methods
(5)
Implementation detail — not part of the public API.
Methods (inherited)
From Object (17)
- # acts_like?
- # blank?
- # deep_dup
- # duplicable?
- # html_safe?
- # in?
- # instance_values
- # instance_variable_names
- # presence
- # presence_in
- # present?
- # to_param
- # to_query
- # try
- # try!
- # unescape
- # with_options
From ActiveRecord::TestFixtures (4)
From ActiveSupport::Concern (3)
- # class_methods
- # included
- # prepended