From: Lloyd Zusman Date: 2005-11-13T03:49:50+09:00 Subject: Re: Converting between Time and DateTime "David A. Black" writes: > Hi -- > > On Sun, 13 Nov 2005, Lloyd Zusman wrote: > >> What is the recommended method for converting between Time objects and >> those of type DateTime? > > OK, let me try again. > > irb(main):068:0> t = Time.now > => Sat Nov 12 13:33:08 EST 2005 > irb(main):069:0> d = DateTime.parse(t.iso8601) > => # > irb(main):070:0> d.strftime("%c") > => "Sat Nov 12 13:33:08 2005" > irb(main):071:0> Time.parse(d.strftime("%c")) > => Sat Nov 12 13:33:08 EST 2005 > > 'parse' seems to be a good bet in both directions. Yes, I thought of these, but they involve converting to and from an intermediate String object. The ones I suggested in my original message are more direct ... although they each require six subsidiary method calls. If I get some extra time, I'll benchmark my versions against these intermediate-String versions. But no matter which is faster, wouldn't it ultimately be better if we had conversion methods built in to the standard classes? Even if we don't unify Time with DateTime, these extra contstructors would be a nice convenience. -- Lloyd Zusman ljz@asfast.com God bless you.