Ruby | Time ctime() function Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The ctime() is an inbuilt method in Ruby returns a canonical string representation of time. Syntax: time.ctime() Parameters: The function accepts no parameter Return Value: It returns a canonical string representation of time. Example 1: CPP # Ruby code for ctime() method # Include Time require 'time' # Declaring time a = Time.new(1993, 02, 24, 12, 0, 0, "+09:00") # Prints time as string puts a.ctime() Output: Wed Feb 24 12:00:00 1993 Example 2: CPP # Ruby code for ctime() method # Include Time require 'time' # Declaring time a = Time.now.ctime() # Prints time as string puts a Output: Tue Aug 27 08:22:03 2019 Comment More infoAdvertise with us Next Article Ruby | Time + function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Time-class Similar Reads Ruby | Time asctime() function The asctime() is an inbuilt method in Ruby returns a canonical string representation of time. Syntax: time.asctime() Parameters: The function accepts no parameter Return Value: It returns a canonical string representation of time. Example 1: CPP # Ruby code for asctime() method # Include Time requir 1 min read Ruby | Time eql?() function The eql?() is an inbuilt method in Ruby returns true if time and other time are both time objects with the same seconds and fractional seconds otherwise false Syntax: time.eql?() Parameters: The function accepts no parameter Return Value: It returns true if time and other time are both time objects 1 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 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 Like