We can get the day of the month in Ruby using the day
method of the Time
object. We can call it on object anytime.
t_o.day
t_o
: The Time
object to get the day of the month.
The day
method returns the day of the month, that is, from 1st to 31st.
Let’s take a look at the code:
# create Time Objectst1 = Time.nowt2 = Time.new(1998)t3 = Time.new(2003, 03, 29)# get the datea = t1.dayb = t2.dayc = t3.day# print resultsputs aputs bputs c
Time.now
which returns the current system time.Time.new
to create a Time
object whose time is in 1998
.Time.new()
method to create another Time
object.day
method on the time objects we created.