Rails datetime_select 带时区
Rails datetime_select with time zone
我正在编写一个简单的日历应用程序,但遇到时区问题。对于许多不错的日期和时间助手,操作视图和活动记录肯定不能很好地处理时区。
我有一个约会模型,其 appointment_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
给出 select 当前日期和时间(UTC),而不是约会日期和时间。 appt_time
确实被调用并且 returns 为时区调整了正确的日期和时间。
文档没有提到时区,什么是最好的实现方式?
看来问题出在您的 select 标记上,而不是时区偏移。看起来你想要
<%= datetime_select "appointment", "appointment_time", default: @appt.appt_time, ampm: true %>
我正在编写一个简单的日历应用程序,但遇到时区问题。对于许多不错的日期和时间助手,操作视图和活动记录肯定不能很好地处理时区。
我有一个约会模型,其 appointment_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
给出 select 当前日期和时间(UTC),而不是约会日期和时间。 appt_time
确实被调用并且 returns 为时区调整了正确的日期和时间。
文档没有提到时区,什么是最好的实现方式?
看来问题出在您的 select 标记上,而不是时区偏移。看起来你想要
<%= datetime_select "appointment", "appointment_time", default: @appt.appt_time, ampm: true %>