Rails 3 用户时区

问题描述:

在 Rails 2.x 中,我不需要特别设置任何时区信息,用户无论在哪个时区,都将获得用户在其操作系统中指定的日期时间.

In Rails 2.x I didn't specifically have to set any timezone info and the user, no matter what timezone they were in, would get the datetime specified by the user in their OS.

现在在 Rails 3 中,一切都以 UTC 显示.是否有可能恢复默认查看行为而不必放入一些 js hack 来检测用户的时区?

Now in Rails 3 everything is displayed in UTC. Is it possible to get back that default viewing behaviour without having to put in some js hack to detect the user's timezone?

谢谢!

克里斯

我发现如果将 localtime 添加到字符串中,您会得到正确的日期时间...

I found that if you add localtime to your string you get the proper date time...

Invoice.last.created_at.localtime