From: Robert Klemme Date: 2011-06-07T23:58:56+09:00 Subject: Re: Ruby 1.9 Time parse question Please do not top post. On Tue, Jun 7, 2011 at 4:48 PM, Paul wrote: > Hello Robert, thank you for the reply. > > I played with Date.strptime but it seems to ignore the time stamps. Clearly, as Date is about _dates_. :-) > I need to use the time stamps to sort the records correctly. My > current code joins the date and time and parses them together using > the Time library so that it can sort it based on date+time stamp. > > Is there a way I can use the Date parser so that it factors in the date > +time? > (if there is, I haven't figured it out yet) My bad. I overlooked that you want time as well. Then use class Time or DateTime instead. They all have method strptime. Legal format patterns are in the docs. > (I wish I could specify format for the Time parsing like I can with > Date parsing) You can. Btw, I'd rather convert strings on insertion into the Array. It's usually best to convert input into specific types when one sees it. Then you can use all the specific Date / Time / DateTime functionality in your application and only convert back to string when you output results. Also, often specific data needs less memory than data left in strings. Also, converting only once is more efficient than doing it over and over again. In your case you could as well use Array#sort_by to convert each timestamp only once. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/