LoginSignup
0

More than 3 years have passed since last update.

【ruby】整数で出力した秒を「00:00:00」の形式で出力

Last updated at Posted at 2019-11-16

動画の開始位置は●秒、終了位置は●秒、その部分の再生時間は?

という計算をしたいと思ったので調べてみました。
「movie_time.strftime('%X')」みたいな感じで簡単にできると思ったら、
Timeメソッドなるものの力を借りなきゃいけないようでした。

time.rb
start = 30
stop = 79
movie_time = stop - start
movie_time = Time.at(movie_time).utc.strftime('%X')
puts movie_time

参考記事

Ruby on Railsで秒で指定した時間を時:分:秒に変換する
https://marketing-web.hatenablog.com/entry/second_to_00-00-00

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0