Ruby | Time year() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report Time#year() : year() is a Time class method which returns the year for time (including the century). Syntax: Time.year() Parameter: Time values Return: year for time (including the century). Example #1 : Ruby # Ruby code for Time.year() method # loading library require 'time' # declaring time a = Time.new(2019) # declaring time b = Time.new(2019, 10) # declaring time c = Time.new(2019, 12, 31) # Time puts "Time a : #{a}\n\n" puts "Time b : #{b}\n\n" puts "Time c : #{c}\n\n\n\n" # year form puts "Time a year form : #{a.year}\n\n" puts "Time b year form : #{b.year}\n\n" puts "Time c year form : #{c.year}\n\n" Output : Time a : 2019-01-01 00:00:00 +0100 Time b : 2019-10-01 00:00:00 +0200 Time c : 2019-12-31 00:00:00 +0100 Time a year form : 2019 Time b year form : 2019 Time c year form : 2019 Example #2 : Ruby # Ruby code for Time.year() method # loading library require 'time' # declaring time a = Time.now # declaring time b = Time.new(1000, 10, 10) # declaring time c = Time.new(2020, 12) # Time puts "Time a : #{a}\n\n" puts "Time b : #{b}\n\n" puts "Time c : #{c}\n\n\n\n" # year form puts "Time a year form : #{a.year}\n\n" puts "Time b year form : #{b.year}\n\n" puts "Time c year form : #{c.year}\n\n" Output : Time a : 2019-08-27 05:57:05 +0200 Time b : 1000-10-10 00:00:00 +0053 Time c : 2020-12-01 00:00:00 +0100 Time a year form : 2019 Time b year form : 1000 Time c year form : 2020 Comment More infoAdvertise with us Next Article Ruby | Time - function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Time-class Similar Reads Ruby | Time yday() function Time#yday() is a Time class method which returns the integer representing the day of the year, 1 to 366. Syntax: Time.yday() Parameter: Time values Return: the day of the year, 1 to 366. Example #1 : Ruby # Ruby code for Time.yday() method # loading library require 'time' # declaring time a = Time.n 2 min read Ruby | Time - function Time#-() is a Time class method which returns a new time value after subtracting seconds from it. Syntax: Time.-() Parameter: Time values Return: new time value after subtracting seconds from it. Example #1 : Ruby # Ruby code for Time.-() method # declaring time a = Time.new(2019) # declaring time b 2 min read Ruby | Time + function Time#+() is a Time class method which returns a new time value after adding seconds to it. Syntax: Time.+() Parameter: Time values Return: new time value after adding seconds to it Example #1 : Ruby # Ruby code for Time.+() method # declaring time a = Time.new(2019) # declaring time b = Time.new(201 2 min read Ruby | Time usec function Time#usec() is a Time class method which returns the number of microseconds for time. Syntax: Time.usec() Parameter: Time values Return: the number of microseconds for time. Example #1 : Ruby # Ruby code for Time.usec() method # loading library require 'time' # declaring time a = Time.new(2019) # de 2 min read Ruby | Time zone() function Time#zone() : zone() is a Time class method which returns the name of the time zone used for time like "UTC", "GMT". Syntax: Time.zone() Parameter: Time values Return: the name of the time zone used for time like "UTC", "GMT" Example #1 : Ruby # Ruby code for Time.zone() method # loading library req 2 min read Ruby | Time wday function Time#wday() is a Time class method which returns the integer representing the day of the week, 0..6, with Sunday == 0. Syntax: Time.wday() Parameter: Time values Return: integer representing the day of the week, 0..6, with Sunday == 0. Example #1 : Ruby # Ruby code for Time.wday() method # loading l 2 min read Like