Rails datetime_select with time zone

时间:2015-12-04 22:19:55

标签: datetime ruby-on-rails-4 timezone

我正在编写一个简单的日历应用程序并遇到时区问题。对于许多不错的日期和时间助手,操作视图和活动记录肯定不适合时区。

我有一个约会模型,其约会时间属性为date_time。

我目前的问题是在表单标记中使用datetime_select编辑appointment_time。

<%= datetime_select :appointment_time, @appt.appt_time,ampm: true %>

def appt_time
  appointment_time.in_time_zone(time_zone) #this is the appointment owners time zone
end

给出一个选择,其中包含UTC的当前日期和时间,而不是约会日期和时间。调用appt_time并返回为时区调整的正确日期和时间。

文档中没有提及时区,实现它的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

看起来问题在于您的选择标记,而不是时区偏移。看起来像你想要的

<%= datetime_select "appointment", "appointment_time", default: @appt.appt_time, ampm: true %>                                                                                                         
相关问题