_parse()
method exists in the standard library of Ruby programming. _parse()
method of Ruby programming describes the given representation of date and time and returns the described elements. To find out the _parse()
of the any given date in Ruby programming, we use date._parse()
method.
date._parse()
Function in Ruby
date._parse()
function exists in Standard Date Library of Ruby. The purpose of this method is to provide the explanation for any given date.
Syntax of the _parse()
Method in Ruby
In date, the syntax of
_parse()
method is:1 | date._parse(x) |
Parameters of date._parse()
Method in Ruby
x
– Where x
is any valid date object. This parameter is required.Note: If the
x
parameter is not a date object, date._parse()
method will return an error
.
Return Value of date._parse()
date._parse()
method will return the parsed elements of any given date.
How to _parse()
Date in Ruby Example 1
1 2 3 4 5 | # import date library require 'date' date = Date._parse('2011-11-23') puts date |
Output
{:year=>2011, :mon=>11, :mday=>23}
How to _parse()
Date in Ruby Example 2
1 2 3 4 5 | # import date library require 'date' date = Date._parse('2011-December-23') puts date |
Output
{:year=>2011, :mon=>12, :mday=>23}
Convert Date to string in _parse()
Method
1 2 3 4 | # import date library require 'date' date = Date._parse('March 16, 2012').to_s puts date |
Output
“2012-03-16”
Adding Time Zone in Ruby _parse()
Method
1 2 3 4 | # import date library require 'date' date = Date._parse('March 16, 2012 02:30 GMT') puts date |
Output
{:zone=>"GMT", :hour=>2, :min=>30, :year=>2012, :mon=>3, :mday=>16, :offset=>0}
Adding Days in _parse()
Method
1 2 3 4 5 | # import date library require 'date' date = Date.parse('March 16, 2012 02:30 GMT').next_day(5) puts date |
Output
2012-03-21
Substracting Days in _parse()
Method
1 2 3 4 5 | # import date library require 'date' date = Date.parse('March 16, 2012 02:30 GMT').prev_day(5) puts date |
Output
2012-03-11