[Ruby] I want the video playback time (HH:MM:SS) to be in seconds and vice versa

less than 1 minute read

HH:MM:SS in seconds

# rails c or require
require "active_support/duration"

duration_text = "00:01:00"
Time.parse(duration_text)-Time.parse("00:00:00") # => 60.0

Seconds to HH:MM:SS

Time.at(60).utc.strftime("%H:%M:%S") # => "00:01:00"

Tags: ,

Updated: