The month() is an inbuilt method in Ruby returns the month of the year for time.
Syntax: time.month()
Parameters: The function accepts no parameter
Return Value: It returns the month of the year for time.
Example 1:
# Ruby code for month() method
# Include Time
require 'time'
# Declaring time
a = Time. new (2000, 12, 23)
# Prints the month of the year for the time
puts a.month()
|
Output:
12
Example 2:
# Ruby code for month() method
# Include Time
require 'time'
# Declaring time
a = Time.now()
# Prints the month of the year for the time
puts a.month()
|
Output:
8
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
07 Jan, 2020
Like Article
Save Article