ruby time date
Time と Date がある
Time
code:a.rb
require "time"
t = Time.new # 現在時刻
str = t.strftime("%Y-%m-%d %H:%M:%S")
# string -> time
p Time.parse("2021-11-30")
時間計測
code:b.rb
start_time = Time.now
code:a.rb
Time.now.to_i # unix time
Time.at(1234567890) # unix time to time
code:a.rb
t = Time.now
t = t + 60 # 1分後
Date
code:a.rb
require "date"
day = Date.today
p day.prev_day(5)
str = day.strftime("%Y-%m-%d %H:%M:%S")