0

私は2つの属性start_timeとを持っていますend_time

start_time入力した日付(時刻を除く)をフィールドに含めるにはどうすればよいですかend_time(開始時刻と終了時刻は同じ日に発生するため、ユーザーに2回入力するように促す意味はありません)。

意見:

<div class="day">
    <div class="field">
       <%= f.label :start_time, "Date"  %>
       <%= f.date_select :start_time,:default => Time.now+1.week, :order => [:month, :day, :year], :ampm => true %>
    </div>
    <div class="field">
        <%= f.label :start_time, "Start Time" %>
        <%= f.time_select :start_time, :ignore_date => true, :minute_step => 15, :ampm => true, :default => Time.now.beginning_of_day + 9.hours %>
    </div>
    <div class="field">
        <%= f.label :end_time, "End Time" %>
        <%= f.time_select :end_time, :minute_step => 15, :ampm => true, :default => Time.now.beginning_of_day + 15.hours %>
    </div>
    <%= link_to_function "Remove this day", "remove_fields(this)" %>
</div>

どんな助けでもいただければ幸いです。

4

1 に答える 1

1

これを行うためのきちんとした方法は本当にありません。個々のコンポーネントを抽出する必要があります。

t1 = start_time
t2 = end_time
t2 = Time.local(t1.year,t1.month,t1.day,t2.hour,t2.min,t2.sec).in_time_zone

作業しているタイムゾーンに注意してください。Time.utcの代わりにを使用する必要がある場合がありTime.localます。

于 2012-04-11T02:14:22.923 に答える