【问题标题】:how to get IST time in heroku using rails app如何使用 Rails 应用程序在 Heroku 中获取 IST 时间
【发布时间】:2018-04-21 08:22:50
【问题描述】:

如何使用 Rails 应用程序在 Heroku 中获取 IST 时间

config.active_record.default_timezone = :local

在 config/environments/development.rb 中。上面的代码将时区从 UTC 更改为 IST。

在 config/environments/production.rb 中

config.active_record.default_timezone = :local

它在heroku中不起作用,为什么?我怎样才能得到 IST 时间。

【问题讨论】:

    标签: ruby ruby-on-rails-4 ruby-on-rails-5 ruby-on-rails-5.1 ruby-on-rails-5.2


    【解决方案1】:

    :local 给出服务器当前所在位置的本地时间。因此,在开发中它给了 IST 时间,但在 Heroku 上它给了 UTC,因为服务器不在印度。

    您可以在 application.rb 中使用config.time_zone = 'New Delhi' 来获取 IST 中的时间。

    【讨论】:

    • /config/application.rb:3:in <top (required)>': undefined local variable or method config' for main:Object (NameError) 当我在 application.rb 文件中使用上述代码时出现错误
    • class Application < Rails::Application 中定义它或者你可以分享你的 application.rb 代码我会帮你定义它。
    • 我正在使用上面的代码,它在本地也很有效,但在 heroku 中不工作它存储相同的 UTC 值。我在 heroku 中没有得到 IST 值。所以帮助我
    • 在上一行下方添加config.active_record.default_timezone = 'New Delhi
    猜你喜欢
    • 1970-01-01
    • 2013-06-25
    • 2013-11-19
    • 2011-03-15
    • 1970-01-01
    • 2012-06-28
    • 2011-07-06
    • 2015-01-01
    • 1970-01-01
    相关资源
    最近更新 更多