Ruby | Time to_date() function Last Updated : 06 Jan, 2020 Comments Improve Suggest changes Like Article Like Report Time#to_date() is a Time class method which returns a self Date object. Syntax: Time.to_date() Parameter: Time values Return: a self Date object. Example #1 : Ruby # Ruby code for Time.to_date() 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" # to_date form puts "Time a to_date form : #{a.to_date}\n\n" puts "Time b to_date form : #{b.to_date}\n\n" puts "Time c to_date form : #{c.to_date}\n\n" Output : Time a : 2019-01-01 00:00:00 +0000 Time b : 2019-10-01 00:00:00 +0000 Time c : 2019-12-31 00:00:00 +0000 Time a to_date form : 2019-01-01 Time b to_date form : 2019-10-01 Time c to_date form : 2019-12-31 Example #2 : Ruby # Ruby code for Time.to_date() 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" # to_date form puts "Time a to_date form : #{a.to_date}\n\n" puts "Time b to_date form : #{b.to_date}\n\n" puts "Time c to_date form : #{c.to_date}\n\n" Output : Time a : 2019-08-27 12:18:20 +0000 Time b : 1000-10-10 00:00:00 +0000 Time c : 2020-12-01 00:00:00 +0000 Time a to_date form : 2019-08-27 Time b to_date form : 1000-10-04 Time c to_date form : 2020-12-01 Comment More infoAdvertise with us Next Article Ruby | Time to_date() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Time-class Similar Reads Ruby | Time to_a() function Time#to_a() is a Time class method which returns the string which returns a ten-element array of values for time. Format [sec, min, hour, day, month, year, wday, yday, isdst, zone] Syntax: Time.to_a() Parameter: Time values Return: a ten-element array of values for time. Example #1 : Ruby # Ruby cod 2 min read Ruby | Time to_datetime() function Time#to_datetime() is a Time class method which returns a date time object of itself. Syntax: Time.to_datetime() Parameter: Time values Return: a date time object of itself. Example #1 : Ruby # Ruby code for Time.to_datetime() method # loading library require 'time' # declaring time a = Time.new(201 2 min read Ruby | DateTime to_time() function DateTime#to_time() : to_time() is a DateTime class method which returns the time object which denotes the DateTime object self. Syntax: DateTime.to_time() Parameter: DateTime values Return: duplicate DateTime object self and resets its to_time. Example #1 : Ruby # Ruby code for DateTime.to_time() me 2 min read Ruby | Time to_f function Time#to_f() : to_f() is a Time class method which returns the value of time as a floating point number of seconds since the Epoch. Syntax: Time.to_f() Parameter: Time values Return: value of time as a floating point number of seconds since the Epoch. Example #1 : Ruby # Ruby code for Time.to_f() met 2 min read Ruby | Time day() function The day() is an inbuilt method in Ruby returns the day of the month for time. Syntax: time.day() Parameters: The function accepts no parameter Return Value: It returns the day of the month for time. Example 1: CPP # Ruby code for day() method # Include Time require 'time' # Declaring time a = Time.n 1 min read Like