The minute of an hour of a time object is from 0 - 59
. One example is 5 minutes, 23 minutes, 59 minutes. etc.
To get this in Ruby, we have to call the min
method on a time object.
t_o.min
t_o: this is the time object we want to get its minutes.
An integer value from 1 - 59 is returned.
# create time objectst1 = Time.now # current timet2 = Time.new(946702800)t3 = Time.new(2002, 10, 31, 2, 2, 2)# get the minutes# and print resultsputs "#{t1.min} minutes"puts "#{t2.min} minutes"puts "#{t3.min} minutes"
Line 2: We created a time object that has a time value of now or current time.
Lines 3-4: We created time objects using the Time.new()
method.
Lines 8-10: We called the min
method on the time objects we created and printed the results.