Open In App

Ruby | Time year() function

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The year() is an inbuilt method in Ruby returns the year for time

Syntax: time.year()

Parameters: The function accepts no parameter

Return Value: It returns the year for time

Example 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()


Output:

2000

Example 2:




# Ruby code for year() method
  
# Include Time
require 'time'
  
# Declaring time 
a = Time.now()
  
# Prints the year for the time
puts a.year()


Output:

2019

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads