Rails 3 用户时区 [英] Rails 3 user timezones

查看:40
本文介绍了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

这篇关于Rails 3 用户时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆