红宝石 |时间月()函数
month()是 Ruby 中的一个内置方法,它返回一年中的月份作为时间。
Syntax: time.month()
Parameters: The function accepts no parameter
Return Value: It returns the month of the year for time.
示例 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()
输出:
12
示例 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()
输出:
8