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.
Time object to get the day of the month.
day method returns the day of the month, that is, from 1st to 31st.
Let’s take a look at the code:
# create Time Objects t1 = Time.now t2 = Time.new(1998) t3 = Time.new(2003, 03, 29) # get the date a = t1.day b = t2.day c = t3.day # print results puts a puts b puts c
Time.nowwhich returns the current system time.
Time.newto create a
Timeobject whose time is in
Time.new()method to create another
daymethod on the time objects we created.
View all Courses