ActiveSupport::TimeWithZone < Object
| Use Case | Command | Description |
|---|---|---|
| 🕒 Create time in a zone | Time.zone.local(2007,2,10,15,30,45) |
Create a local time in the current zone |
| 📅 Parse string in zone | Time.zone.parse('2007-02-10 15:30:45') |
Parse a string into a time in the zone |
| ⏰ Create from timestamp | Time.zone.at(1171139445) |
Create a time from a Unix timestamp in the zone |
| 🕐 Current time in zone | Time.zone.now |
Get the current time in the zone |
| 🔄 Convert to time zone | time.in_time_zone |
Convert a Time or DateTime to a TimeWithZone |
| ➕ Add duration | t + 1.day |
Add a duration (ActiveSupport::Duration) |
| 📏 Compare times | t > Time.utc(1999) |
Compare with another Time |
| 🔍 Access parts | t.hour, t.dst?, t.utc_offset, t.zone |
Access hour, DST flag, UTC offset, and zone name |
| 📄 Format output | t.to_s(:rfc822), t.iso8601, t.httpdate |
Format the time in standard formats |
| ⏳ Beginning of year | t.beginning_of_year |
Get the start of the year (returns TimeWithZone) |
🕐 A 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
PRECISIONS: [not documented]
SECONDS_PER_DAY: [not documented]
namenew+-<=>acts_like_time?advanceagoas_jsonbetween?blank?changecomparable_timedst?eql?formatted_offsetfreezefuture?getgmgetlocalgetutcgmt?gmt_offsetgmtimegmtoffhashhttpdateinin_time_zoneinspectis_a?isdstiso8601kind_of?localtimemarshal_dumpmarshal_loadmethod_missingnext_day?past?periodprev_day?respond_to?respond_to_missing?rfc2822rfc3339rfc822sincestrftimetimetime_zoneto_ato_datetimeto_fto_formatted_sto_ito_rto_sto_timetoday?tomorrow?tv_secutcutc?utc_offsetxmlschemayesterday?zoneattr_reader time_zone
Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-27 16:41 @216.73.216.194
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format