Skip to content

Instantly share code, notes, and snippets.

@jjb
Last active December 14, 2015 06:29
Show Gist options
  • Save jjb/5043361 to your computer and use it in GitHub Desktop.
Save jjb/5043361 to your computer and use it in GitHub Desktop.
There are a few nice guides to timezones in Rails apps (http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails, http://danilenko.org/2012/7/6/rails_timezones/), but these might be overwhelming if you just want to quickly set and work with a timezone without caring about configuring it app-wide. So, here you go:
# First do this
Time.zone = 'EST'
# Now you can do this
Time.zone.now
# and this!
Time.zone.local(2013, 1, 1)
# rails/activerecord/arel work with it:
FooBar.where('created_at > ?' Time.zone.local(2012, 1, 1))
# yay!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment