Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

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

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

という計算をしたいと思ったので調べてみました。
「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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?