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
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);
}
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.