Ruby: combine Date and Time objects into a DateTime

I found this, but it’s not as elegant you would hope:

d = Date.new(2012, 8, 29)
t = Time.now
dt = DateTime.new(d.year, d.month, d.day, t.hour, t.min, t.sec, t.zone)

By the way, the ruby Time object also stores a year, month, and day, so you would be throwing that away when you create the DateTime.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)