Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Time#localtime
(?::String utc_offset) -> ::Time
localtime → self
localtime(zone) → self
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 already a local time. -
Otherwise returns
self, converted to 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 self, converted 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.