0

我正在尝试将日期和时间字段从表单保存并转换为单个日期时间属性。目前我正在通过以下日期和时间

Parameters: {"utf8"=>"✓", "authenticity_token"=>"4vsUi3DN9ucsxkrojPMe/J4tvJwsIebvGzv0gC0/w8g=", "event"=>{"team_id"=>"4", "date"=>"Monday, July 01, 2013", "time"=>"06:15 am", "event"=>"1", "location_name"=>"Another Loc", "duration"=>"10", "arrival_time"=>"10", "opponent_name"=>"Test", "home_or_away"=>"Home"}, "commit"=>"Create Event"}

并尝试使用以下方法保存此数据

params[:event][:datetime] = DateTime.parse(params[:event][:date]+params[:event][:time])
    @event = Event.new(params[:event])

这似乎可以正确保存数据,但是当我尝试使用以下内容显示它时,我得到的时间是未来 10 小时

Time::DATE_FORMATS[:event_time] = '%l:%M %p'
4

1 回答 1

-1
time_to_merge = Time.new
date_to_merge = Date.today
merged_datetime = DateTime.new(date_to_merge.year, date_to_merge.month,
                               date_to_merge.day, time_to_merge.hour,
                               time_to_merge.min, time_to_merge.sec)
于 2014-12-12T01:26:27.220 回答