APIdock / Ruby
/
method

zone_offset

ruby latest stable - Class: Time
zone_offset(zone, year=self.now.year)
public

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.

# File lib/time.rb, line 134
 def zone_offset(zone, year=self.now.year)
 off = nil
 zone = zone.upcase
 if /\A([+-])(\d\d)(:?)(\d\d)(?:33円((\d\d))?\z/ =~ zone
 off = (1ドル == '-' ? -1 : 1) * ((2ドル.to_i * 60 + 4ドル.to_i) * 60 + 5ドル.to_i)
 elsif /\A[+-]\d\d\z/ =~ zone
 off = zone.to_i * 3600
 elsif ZoneOffset.include?(zone)
 off = ZoneOffset[zone] * 3600
 elsif ((t = self.local(year, 1, 1)).zone.upcase == zone rescue false)
 off = t.utc_offset
 elsif ((t = self.local(year, 7, 1)).zone.upcase == zone rescue false)
 off = t.utc_offset
 end
 off
 end

AltStyle によって変換されたページ (->オリジナル) /