在服务器本地时间中保存 Rails 3 时间以支持非时区感知系统
由于现有数据或纯粹本地访问且不了解时区的遗留/连接系统存在兼容性问题,我们中的一些人无法存储和使用 UTC 时间。
一种方法是在 Rails 中禁用 UTC 保存时间,许多人都尝试过但没有找到方法,我以前没有见过。
我们如何覆盖 Rails 3 中的 UTC 时间节省?
您如何处理系统中的此类问题?
Some of us are unable to store and work with time in UTC because of compatibility issues with existing data or legacy/connected systems that are purely accessed locally and non-timezone aware.
1 way is to disable saving time in UTC in rails which many have tried but not found the way to do it, I have not seen any before.
How can we override the UTC time saving in rails 3?
How do you manage such an issue in your system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下配置组合,
我发现使用 MSSql 后端在我的应用程序上工作的是application.rb 中的
时间是根据服务器时间保存的,没有转换为 UTC 并相应地显示。
我还没有尝试过使用任何其他数据库后端。
也许另一种解决方案是创建供 Rails 使用的专用时间列,并使用触发器在这些 UTC 时间数据与另一组时间列(本地时间)之间进行同步,以支持旧版和非时区感知系统。
What I found to be working on my app with MSSql backend is the following combination of configs
I have in application.rb
time was saved as per the server time, without conversion to UTC and displayed accordingly.
I have not tried this with any other database backends.
Perhaps an alternative solution is to create dedicated time columns for use by rails and use triggers to sync between these UTC time data with another set of time columns(in local time) in order to support legacy and non-timezone aware systems.