Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Time.zone_offset

zone_offset(zone, year=self.now.year)

Return the number of seconds the specified time zone differs from UTC.

Numeric time zones that include minutes, such as -10:00 or +1330 will work, as will simpler hour-only time zones like -10 or +13.

Textual time zones listed in ZoneOffset are also supported.

If the time zone does not match any of the above, zone_offset will check if the local time zone (both with and without potential Daylight Saving Time changes being in effect) matches zone. Specifying a value for year will change the year used to find the local time zone.

If zone_offset is unable to determine the offset, nil will be returned.

Example
require 'time'

Time.zone_offset("EST") #=> -18000

You must require ‘time’ to use this method.

See also .xmlschema #+ .utc #- also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0