gpt4 book ai didi

ruby-on-rails - time_select 表单助手将新时间对象解释为 UTC 而不是配置的时区

转载 作者:行者123 更新时间:2023-12-04 21:23:03 25 4
gpt4 key购买 nike

我遇到了对我来说似乎很简单的问题,但我无法弄清楚我做错了什么。在我的应用程序中,用户可以通过一个简单的 form_for 添加他们的类(class)。他们可以为类(class)的讲座输入 start_time 和 end_time,如下所示:

<div class="field">
Start Time<br />
<%= time_select :course, :start_time, { :minute_step => 5, :ampm => true } %>
</div>

<div class="field">
End Time<br />
<%= time_select :course, :end_time, { :minute_step => 5, :ampm => true } %>
</div>

我将 application.rb 中的时区配置为东部时间,这似乎可以正常工作,因为 created_at 在正确的时区中返回。

但是,我遇到的问题是 start_time 和 end_time 作为 UTC 输入到数据库中。因此,当用户选择在上午 10 点开始上课时,输入的时间为 10 UTC 而不是 10 AM EST/15:00 UTC。我在这里缺少什么?看起来我想要发生的事情应该是可能的。

最佳答案

总结评论中的答案,以便从“未回答”过滤器中删除此问题:

推荐人 Tim Brandes :

Maybe this helps you: Timezone with rails 3 ... I have never used a time_select but always a datetime_select when dealing with timezones, maybe this could be an issue, but it seems rather unlikely.



适用于 Philip V 的解决方案:

My start_time and end_time are not being saved within the time zone but saved as a UTC time. ... I changed the column type for start_time and end_time to datetime and this fixed the issues I had. I guess time columns only allow UTC.

关于ruby-on-rails - time_select 表单助手将新时间对象解释为 UTC 而不是配置的时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8745960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com