I want to set the video playback time (HH: MM: SS) to seconds, and vice versa.

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"

Recommended Posts

I want to set the video playback time (HH: MM: SS) to seconds, and vice versa.
I translated the grammar of R and Java [Updated from time to time]
I want to recursively get the superclass and interface of a certain class
I want to truncate after the decimal point
I want to get the value in Ruby
I want to hit the API with Rails on multiple docker-composes set up locally