Ruby | DateTime to_datetime() function Last Updated : 09 Jan, 2020 Comments Improve Suggest changes Like Article Like Report DateTime#to_datetime() : to_datetime() is a DateTime class method which returns the self DateTime object. Syntax: DateTime.to_datetime() Parameter: DateTime values Return: the self DateTime object. Example #1 : Ruby # Ruby code for DateTime.to_datetime() method # loading library require 'date' # declaring DateTime value date_a = DateTime.new(2019, 8, 10, 4, 10, 9) # declaring DateTime value date_b = DateTime.new(2019, 8, 10.5) # declaring DateTime value date_c = DateTime.new(2019, 8, 10, 4, 10, 9, Rational(4, 24)) # to_datetime method puts "DateTime to_datetime form : #{date_a.to_datetime}\n\n" puts "DateTime to_datetime form : #{date_b.to_datetime}\n\n" puts "DateTime to_datetime form : #{date_c.to_datetime}\n\n" Output : DateTime to_datetime form : 2019-08-10T04:10:09+00:00 DateTime to_datetime form : 2019-08-10T12:00:00+00:00 DateTime to_datetime form : 2019-08-10T04:10:09+04:00 Example #2 : Ruby # Ruby code for DateTime.to_datetime() method # loading library require 'date' # declaring DateTime value date_a = DateTime.new(2019, 8, 10, 5) # declaring DateTime value date_b = DateTime.parse('10 Aug 2018 04:10:06+04:30') # declaring DateTime value date_c = DateTime.new(2019, 8, 10, 4, 10, 9, '+03:00') # to_datetime method puts "DateTime to_datetime form : #{date_a.to_datetime}\n\n" puts "DateTime to_datetime form : #{date_b.to_datetime}\n\n" puts "DateTime to_datetime form : #{date_c.to_datetime}\n\n" Output : DateTime to_datetime form : 2019-08-10T05:00:00+00:00 DateTime to_datetime form : 2018-08-10T04:10:06+04:30 DateTime to_datetime form : 2019-08-10T04:10:09+03:00 Comment More infoAdvertise with us Next Article Ruby | DateTime to_datetime() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby DateTime-class Similar Reads Ruby | DateTime to_date() function DateTime#to_date() : to_date() is a DateTime class method which returns the Date object which denotes itself. Syntax: DateTime.to_date() Parameter: DateTime values Return: the Date object which denotes itself. Example #1 : Ruby # Ruby code for DateTime.to_date() method # loading library require 'dat 2 min read Ruby | DateTime to_s() function DateTime#to_s() : to_s() is a DateTime class method which returns string representation of the DateTime object. Syntax: DateTime.to_s() Parameter: DateTime values Return: string representation of the DateTime object. Example #1 : Ruby # Ruby code for DateTime.to_s() method # loading library require 2 min read Ruby | Date asctime() function Date#asctime() is a Date class method which returns the string in asctime format. It is equivalent to strftime('%c').the astronomical modified Julian day number. Syntax: Date.asctime() Parameter: Date values Return: the string in asctime format. strftime('%c').the astronomical modified Julian day nu 2 min read Ruby | Date ctime() Function Date#ctime() is a Date class method which returns a string in asctime format and is equivalent to strftime('%c'). Syntax: Date.ctime() Parameter: Date values Return: a string in asctime format and is equivalent to strftime('%c'). Example #1 : Ruby 1=1 # Ruby code for Date.ctime() method # loading da 2 min read Ruby | DateTime zone() function DateTime#zone() : zone() is a DateTime class method which returns the time zone for a given DateTime object. Syntax: DateTime.zone() Parameter: DateTime values Return: the time zone for a given DateTime object. Example #1 : Ruby # Ruby code for DateTime.zone() method # loading library require 'date' 2 min read Like