Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Time#localtime

time.localtime → time
time.localtime(utc_offset) → time

Converts time to local time (using the local time zone in effect at the creation time of time) modifying the receiver.

If utc_offset is given, it is used instead of the local time.

Example
t = Time.utc(2000, "jan", 1, 20, 15, 1) #=> 2000-01-01 20:15:01 UTC
t.utc?                                  #=> true

t.localtime                             #=> 2000-01-01 14:15:01 -0600
t.utc?                                  #=> false

t.localtime("+09:00")                   #=> 2000-01-02 05:15:01 +0900
t.utc?                                  #=> false

If utc_offset is not given and time is local time, just returns the receiver.

See also #iso8601 #mday #isdst #min also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1