In the past, time zones have been very difficult to work with, but no longer! Rails 2.1 brings with it great time zone support as you can see in this episode.
rake time:zones:local
# config/environment.rb
config.time_zone = "Pacific Time (US & Canada)"
# controllers/application.rb
before_filter :set_user_time_zone
private
def set_user_time_zone
Time.zone = current_user.time_zone if logged_in?
end
# in migration file
add_column :users, :time_zone, :string
<!-- users/new.html.erb -->
<%= f.time_zone_select :time_zone, TimeZone.us_zones %>
Rails 2.1 版本引入了强大的时区支持功能,简化了开发者处理时区问题的过程。通过配置文件及用户设置,可以轻松实现应用程序中时区的本地化。

被折叠的 条评论
为什么被折叠?



