Ruby | DateTime parse() function Last Updated : 09 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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 for DateTime.parse() method # loading library require 'date' # declaring DateTime value date_a = DateTime.parse('20180403T030908+0700') # declaring DateTime value date_b = DateTime.parse('2019-04-03T04:04:02+08:00') # parse method puts "DateTime parse form : #{date_a}\n\n" puts "DateTime parse form : #{date_b}\n\n" Output : DateTime parse form : 2018-04-03T03:09:08+07:00 DateTime parse form : 2019-04-03T04:04:02+08:00 Example #2 : Ruby # Ruby code for DateTime.parse() method # loading library require 'date' # declaring DateTime value date_a = DateTime.parse('3rd Feb 2001 04:05:06 PM') # declaring DateTime value date_b = DateTime.parse('10 Aug 2018 04:10:06+04:30') # declaring DateTime value date_c = DateTime.parse('20010203T040506+03:00') # parse method puts "DateTime parse form : #{date_a}\n\n" puts "DateTime parse form : #{date_b}\n\n" puts "DateTime parse form : #{date_c}\n\n" Output : DateTime parse form : 2001-02-03T16:05:06+00:00 DateTime parse form : 2018-08-10T04:10:06+04:30 DateTime parse form : 2001-02-03T04:05:06+00:00 Comment More infoAdvertise with us Next Article Ruby | DateTime parse() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby DateTime-class Similar Reads 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 httpdate() function DateTime#httpdate() : httpdate() is a DateTime class method which returns a new DateTime object by parsing from a string according to some RFC 2616 format. Syntax: DateTime.httpdate() Parameter: DateTime values Return: A new DateTime object by parsing from a string according to some RFC 2616 format. 1 min read Ruby | DateTime offset() function DateTime#offset() is a DateTime class method which returns the DateTime object offset. Syntax: DateTime.offset() Parameter: DateTime values Return: the DateTime object offset. Example #1 : Ruby # Ruby code for DateTime.offset() method # loading library require 'date' # declaring DateTime value date_ 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 jd() function DateTime#jd() : jd() is a DateTime class method which returns a DateTime object denoting the given chronological Julian day number. Syntax: DateTime.jd() Parameter: DateTime values Return: DateTime object denoting the given chronological Julian day number. Example #1 : Ruby # Ruby code for DateTime. 1 min read Like