我正在编写一个简单的日历应用程序,并且遇到时区问题.对于许多不错的日期和时间助手,操作视图和活动记录肯定不能与时区配合使用.
I am writing a simple calendar app and having troubles with time zones. For as many nice Date and Time helpers, action view and active record sure don't play nice with time zones.
我有一个约会模型,其约会时间为datetime.
I have an appointment model with the appointment_time attribute which is a datetime.
我当前的问题是在表单标签中使用datetime_select编辑约会时间.
My current issue is editing appointment_time with datetime_select within a form tag.
<%= 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 会被调用并返回针对时区调整的正确日期和时间.
gives a select with the current date and time in UTC, not the appointment date and time. appt_time does get called and returns the correct date and time adjusted for the time zone.
文档中没有提到时区,什么是最好的方法?
The docs mention nothing about time zones, what is the best way to accomplish it?
推荐答案问题似乎出在您的select标签上,而不是时区偏移量上.看起来像你想要的
It looks like the problem is with your select tag, not the time zone offset. Looks like you want
<%= datetime_select "appointment", "appointment_time", default: @appt.appt_time, ampm: true %>更多推荐
Rails datetime
发布评论