Ruby/Time/Day Light Saving

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

Checking Whether Daylight Saving Time Is Currently in Effect

puts Time.local(2006, 1, 1)                  # => Sun Jan 01 00:00:00 EST 2006
puts Time.local(2006, 1, 1).isdst            # => false
puts Time.local(2006, 10, 1)                 # => Sun Oct 01 00:00:00 EDT 2006
puts Time.local(2006, 10, 1).isdst           # => true



Except for the Navajo Nation, Arizona doesn"t use Daylight Saving Time.

ENV["TZ"] = "America/Phoenix"
arizona = Time.local(2006, 10, 1)      # => Sun Oct 01 00:00:00 MST 2006
arizona.isdst                          # => false



Is daylight saving time

eastern = Time.local(2006, 10, 1)      # => Sun Oct 01 00:00:00 EDT 2006
eastern.isdst                          # => true



Is daylight saving time by time zone

ENV["TZ"] = "US/Pacific"
pacific = Time.local(2006, 10, 1)      # => Sun Oct 01 00:00:00 PDT 2006
pacific.isdst                          # => true



restore the original time zone.

ENV["TZ"] = nil