Skip to content

Instantly share code, notes, and snippets.

@wnuqui wnuqui/gist:3038677

Created Jul 3, 2012
Embed
What would you like to do?
in the zone
# 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
You can’t perform that action at this time.