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
time.c
View on GitHub ↗
static VALUE
time_localtime_m(int argc, VALUE *argv, VALUE time)
{
VALUE off;
if (rb_check_arity(argc, 0, 1) && !NIL_P(off = argv[0])) {
return time_zonelocal(time, off);
}
return time_localtime(time);
}
With no argument given:
-
Returns
selfifselfis a local time. -
Otherwise returns a new
Timein the user’s local timezone:Examplet = 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.