From: Peter Vandenabeele Date: 2012-01-18T00:43:51+09:00 Subject: Re: Parsing log with date time entry --00248c6a6726896a8d04b6bb3217 Content-Type: text/plain; charset=UTF-8 On Tue, Jan 17, 2012 at 4:37 PM, Peter Vandenabeele wrote: > On Tue, Jan 17, 2012 at 4:26 PM, Christopher Graves wrote: > >> Robert Klemme wrote in post #1041261: >> > On Mon, Jan 16, 2012 at 11:56 PM, Christopher Graves >> > wrote: >> >> >> >> What would be the best way to get the current time formatted per the >> log >> >> entries and collect a range of times say from current to 15 minutes >> >> previously. >> > >> > I am not sure what you mean by "collect a range". Parsing can be done >> > like this: >> > >> > require 'time' >> > t = Time.strptime('01/10/2012 14:46:02:86', '%m/%d/%Y %H:%M:%S:%L') >> > >> > Cheers >> > >> > robert >> >> Thanks Robert, >> >> By collect range, how would I say subtract 15 minutes from the current >> time so that I can collect all matches from 14:31:02 through 14:46:02? >> > > 1.9.3p0 :006 > Time.now.to_s > => "2012-01-17 16:36:06 +0100" > 1.9.3p0 :007 > (Time.now - (15*60)).to_s > => "2012-01-17 16:21:09 +0100" > Actually, for log files, it may be better to use uniform UTC times. So, no confusion on summer/winter time or servers in different part of the world etc. 1.9.3p0 :029 > Time.now.utc.to_s => "2012-01-17 15:43:25 UTC" 1.9.3p0 :030 > (Time.now - (15*60)).utc.to_s => "2012-01-17 15:28:30 UTC" HTH, Peter --00248c6a6726896a8d04b6bb3217--