resources:
- http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails
- http://guides.rubyonrails.org/configuring.html
# Set `Time.zone` default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is `UTC`.
config.time_zone = 'Beijing'
# config.active_record.default_timezone determines whether to use Time.local (if set to :local) or Time.utc (if set to :utc) when pulling dates and times from the database. The default is :utc for Rails, although Active Record defaults to :local when used outside of Rails.
So if you config an incorrent config.time_zone
for rails application, must beware that your have alreally store an incorrent time date to db (utc
to store db, and auto convert your app time zone when call 'object_instance.time_field').
if you have work in corrent yeat, when compare time from db 'object_instance.time_field' and DateTime
or Time
(from PC time) must covert pc time to app time zone, eg:
# whether current gx_grade_score_daily need_reset
# return [:boolean]
def need_reset?
# updated_at.midnight < DateTime.now.midnight
# will inconsistent with really machine time
# updated_at.midnight < Time.now.in_time_zone.midnight
updated_at.localtime.midnight < Time.now.midnight
end