Converting float to mintues

Hi,

I am subtracting 2 times which gives me the time difference in seconds as a float.

How to I convert something like 3.815824 into 0:03 minutes?

Thanks in advance!

Cheers, Chris.

Hi Chris,

How to I convert something like 3.815824 into 0:03 minutes?

There's nothing I know of 'in the can' for that level of granularity, but take a look at the source for distance_of_time_in_words helper (at api.rubyonrails.org). That should put you on the right track.

hth, Bill

require 'rubygems' require 'ruby-units'

a = time1 b = time2 c = (time1 -time2).unit('min') c.to_s('%H:%M") #=> '00:03'

This works well if you need to do math on the units, or if you have to deal with a wide variety of units.

_Kevin

Hi Kevin,

_Kevin wrote:

require 'ruby-units'

a = time1 b = time2 c = (time1 -time2).unit('min') c.to_s('%H:%M") #=> '00:03'

That's cool. Where is ruby-units documented?

Thanks, Bill

It's a gem.

http://www.rubyforge.org/projects/ruby-units