From: Clement Ow Date: 2008-04-17T10:38:44+09:00 Subject: Re: Calculating elapsed time Thanks guys of the prompt reply! However, i'll need help the explanations though.. Really appreciate that ;) Jes炭s Gabriel y Gal叩n wrote: > On Wed, Apr 16, 2008 at 4:47 PM, Rob Biedenharn > wrote: > >> or: >> irb> start = Time.now >> => Wed Apr 16 10:41:03 -0400 2008 >> irb> finish = Time.now >> => Wed Apr 16 10:45:53 -0400 2008 >> irb> elapsed = finish.to_f - start.to_f # note to_f to keep fractional >> seconds > > Yep, I assumed he wanted to stop at the seconds level. > >> => 289.695813894272 >> irb> mins, secs = elapsed.divmod 60.0 >> => [4, 49.6958138942719] >> irb> puts("%3d:%04.2f"%[mins.to_i, secs]) how this line work? "%3d" and %04.2f" means selecting min and secs respectively? >> 4:49.70 >> => nil > > I always forget about divmod, it's a cool little method :-) > > Jesus. -- Posted via http://www.ruby-forum.com/.