Ruby | DateTime rfc3339() function Last Updated : 09 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report DateTime#rfc3339() : rfc3339() is a DateTime class method which returns the rfc3339 standard value of DateTime object. It is equivalent to strftime('%FT%T%:z'). Syntax: DateTime.rfc3339() Parameter: DateTime values Return: rfc3339 standard value of DateTime object. Example #1 : Ruby # Ruby code for DateTime.rfc3339() 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)) # rfc3339 method puts "DateTime rfc3339 form : #{date_a.rfc3339}\n\n" puts "DateTime rfc3339 form : #{date_b.rfc3339}\n\n" puts "DateTime rfc3339 form : #{date_c.rfc3339}\n\n" Output : DateTime rfc3339 form : 2019-08-10T04:10:09+00:00 DateTime rfc3339 form : 2019-08-10T12:00:00+00:00 DateTime rfc3339 form : 2019-08-10T04:10:09+04:00 Example #2 : Ruby # Ruby code for DateTime.rfc3339() 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') # rfc3339 method puts "DateTime rfc3339 form : #{date_a.rfc3339}\n\n" puts "DateTime rfc3339 form : #{date_b.rfc3339}\n\n" puts "DateTime rfc3339 form : #{date_c.rfc3339}\n\n" Output : DateTime rfc3339 form : 2019-08-10T05:00:00+00:00 DateTime rfc3339 form : 2018-08-10T04:10:06+04:30 DateTime rfc3339 form : 2019-08-10T04:10:09+03:00 Comment More infoAdvertise with us Next Article Ruby | DateTime new() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby DateTime-class Similar Reads Ruby | DateTime rfc822() function DateTime#rfc822() : rfc822() is a DateTime class method which returns a new DateTime object by parsing from a string according to some typical RFC 2822 formats. Syntax: DateTime.rfc822() Parameter: DateTime values Return: a new DateTime object by parsing from a string according to some typical RFC 2 1 min read Ruby | DateTime rfc2822() function DateTime#rfc2822() : rfc2822() is a DateTime class method which returns a new DateTime object by parsing from a string according to some typical RFC 3339 formats. Syntax: DateTime.rfc2822() Parameter: DateTime values Return: A new DateTime object by parsing from a string according to some typical RF 1 min read Ruby | DateTime hour() function DateTime#hour() : hour() is a DateTime class method which returns the hours i.e. from 0 to 23 from the given DateTime object. Syntax: DateTime.hour() Parameter: DateTime values Return: hours i.e. from 0 to 23 from the given DateTime object Example #1 : Ruby # Ruby code for DateTime.hour() method # l 2 min read Ruby | DateTime parse() function DateTime#parse() : parse() is a DateTime class method which parses the given representation of date and time, and creates a DateTime object. Syntax: DateTime.parse() Parameter: DateTime values Return: given representation of date and time, and creates a DateTime object. Example #1 : Ruby # Ruby code 1 min read Ruby | DateTime new() function DateTime#new() : new() is a DateTime class method which returns a DateTime object denoting the given calendar date. Syntax: DateTime.new() Parameter: DateTime values Return: a DateTime object denoting the given calendar date. Example #1 : Ruby # Ruby code for DateTime.new() method # loading library 2 min read Ruby | DateTime now() function DateTime#now() : now() is a DateTime class method which returns a DateTime object denoting the given calendar date. Syntax: DateTime.now() Parameter: DateTime values Return: DateTime object denoting the given calendar date. Example #1 : Ruby # Ruby code for DateTime.now() method # loading library re 1 min read Like