After collecting info from the following form:
What's the ea开发者_JAVA技巧siest way to piece together the two parts into a single date object in Ruby? (I wrote some crappy way to do this, and is curious if there is a cleaner method)
require 'date'
date, time = %w(2011-02-26 17:00)
dt = DateTime.parse("#{date} #{time}:00")
dt.to_s # => 2011-02-26T17:00:00+00:00
Note the assumption of UTC; you'll have to append your own time zone if needed.
>> Time.local(*("2011-02-26".split("-") + "17:00".split(":")))
=> Sat Feb 26 17:00:00 0100 2011
>> Time.parse(["2011-02-26", "17:00"].join(" "))
=> Sat Feb 26 17:00:00 0100 2011
If you have 2010-02-26 as params[:date] and 17:00 as params[:time], then you can do
Time.parse("#{params[:date] #{params[:time]}}")
精彩评论