Type:
Class

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 EST -05:00
Time.zone.parse('2007-02-10 15:30:45')          # => Sat, 10 Feb 2007 15:30:45 EST -05:00
Time.zone.at(1170361845)                        # => Sat, 10 Feb 2007 15:30:45 EST -05:00
Time.zone.now                                   # => Sun, 18 May 2008 13:07:55 EDT -04:00
Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone  # => Sat, 10 Feb 2007 15:30:45 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 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 EDT -04:00
t.beginning_of_year                   # => Tue, 01 Jan 2008 00:00:00 EST -05:00
t > Time.utc(1999)                    # => true
t.is_a?(Time)                         # => true
t.is_a?(ActiveSupport::TimeWithZone)  # => true
strftime

strftime(format) Instance Public methods Replaces %Z and %z

2015-06-20 00:00:00
rfc2822

rfc2822() Instance Public methods Returns a string of the object's date and

2015-06-20 00:00:00
localtime

localtime() Instance Public methods Returns a Time.local() instance

2015-06-20 00:00:00
xmlschema

xmlschema(fraction_digits = 0) Instance Public methods Also aliased as:

2015-06-20 00:00:00
time

time() Instance Public methods Returns a

2015-06-20 00:00:00
to_a

to_a() Instance Public methods

2015-06-20 00:00:00
gmtime

gmtime() Instance Public methods Alias for:

2015-06-20 00:00:00
-

-(other) Instance Public methods

2015-06-20 00:00:00
utc?

utc?() Instance Public methods Returns true if the current time zone is set

2015-06-20 00:00:00
to_datetime

to_datetime() Instance Public methods

2015-06-20 00:00:00