Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Kelyarsky Evgeniy http://payplay.fm

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Ruby method to get seconds from colon-separated time string

// converts colon-separated time to seconds
// "01:02:03" => 3723

   1  
   2  def colon_separated_to_i(str)
   3  
   4    time_arr = []
   5    time_arr = str.split(":").reverse
   6    sec = 0
   7    secs = [1, 60, 60*60, 60*60*24]
   8  
   9    time_arr.size.times do {|i|
  10      sec += secs[i].to_i * time_arr[i].to_i
  11    end
  12    sec
  13  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS