Created
July 3, 2012 09:13
-
-
Save wnuqui/3038677 to your computer and use it in GitHub Desktop.
in the zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# default zone | |
Time.zone # => (GMT+00:00) UTC | |
# then we can assign zone like use "Hawaii" | |
Time.zone = "Hawaii" # => "Hawaii" | |
# then do local using zone | |
local = Time.zone.local(2012, 8, 1, 15, 30, 45) # => Wed, 01 Aug 2012 15:30:45 HST -10:00 | |
# then save this local to a column and save | |
# (it will be converted auto to UTC by rails when save in table) | |
# take note our Time.zone is still "Hawaii" so | |
activity = Activity.first | |
activity.update_attribute :created_at, Time.zone.local(2007, 2, 1, 15, 30, 45) | |
# and when | |
activity.created_at # => Wed, 01 Aug 2007 15:30:45 HST -10:00 | |
# now change back Time.zone to UTC | |
Time.zone = 'UTC' | |
# and do | |
activity.created_at # => Thu, 02 Aug 2007 01:30:45 UTC +00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment