Came up with this snippet while writing a Rails log file parser. It will take any number of seconds and convert it to Xm Xs format (which was useful for my display purposes):

def convert_seconds_to_time(seconds)
   total_minutes = seconds / 1.minutes
   seconds_in_last_minute = seconds - total_minutes.minutes.seconds
   "#{total_minutes}m #{seconds_in_last_minute}s"
end

convert_seconds_to_time(630)
=>"10m 30s"

I didn't need to but obviously it can be modified easily to allow for hours as well. This is small and trivial but useful.

Related posts:

  1. Suppressing SQL Logs in Rails
  2. Deployment Using Capistrano / Webistrano via Rails / Phusion Passenger
  3. Using RCov to test Rails
  4. Ruby On Rails and SliceHost Part 1: Initial Setup