Method: Time#localtime

Defined in:
time.c

#localtimeself, Time #localtime(zone) ⇒ Time

With no argument given:

  • Returns self if self is a local time.

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

    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:

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.

Overloads:

  • #localtimeself, Time

    Returns:

  • #localtime(zone) ⇒ Time

    Returns:



4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
# File 'time.c', line 4153

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