红宝石 |时间年()函数
year()是 Ruby 中的一个内置方法,它返回年份作为时间
Syntax: time.year()
Parameters: The function accepts no parameter
Return Value: It returns the year for time
示例 1 :
# Ruby code for year() method
# Include Time
require 'time'
# Declaring time
a = Time.new(2000, 12, 23)
# Prints the year for the time
puts a.year()
输出:
2000
示例 2 :
# Ruby code for year() method
# Include Time
require 'time'
# Declaring time
a = Time.now()
# Prints the year for the time
puts a.year()
输出:
2019