instance method
Time#zone
() -> ::String?
time.zone → string or timezone
time.c
View on GitHub ↗
static VALUE
time_zone(VALUE time)
{
struct time_object *tobj;
VALUE zone;
GetTimeval(time, tobj);
MAKE_TM(time, tobj);
if (TZMODE_UTC_P(tobj)) {
return rb_usascii_str_new_cstr("UTC");
}
zone = tobj->vtm.zone;
if (NIL_P(zone))
return Qnil;
if (RB_TYPE_P(zone, T_STRING))
zone = rb_str_dup(zone);
return zone;
}
Returns the string name of the time zone for self:
Example
Time.utc(2000, 1, 1).zone # => "UTC" Time.new(2000, 1, 1).zone # => "Central Standard Time"
Ruby version changes
-
3.4
-
On Windows, now
Time#zoneencodes the system timezone name in UTF-8 instead of the active code page, if it contains non-ASCII characters. [Bug #20929]
-