Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Time#localtime

(?::String utc_offset) -> ::Time
localtime → self or new_time
localtime(zone) → new_time

With no argument given:

  • Returns self if self is a local time.

  • Otherwise returns a new Time in the user’s local timezone:

    Example
    t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC
    t.localtime                         # => 2000-01-01 14:15:01 -0600
    

With argument zone given, returns the new Time object created by converting self to the given time zone:

Example
t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC
t.localtime("-09:00")               # => 2000-01-01 11:15:01 -0900

For forms of argument zone, see Timezone Specifiers.

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