Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Ruby – _parse() Function – Examples & Explanation

_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:

 

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


Output
{:year=>2011, :mon=>11, :mday=>23}

 

How to _parse() Date in Ruby Example 2


Output
{:year=>2011, :mon=>12, :mday=>23}

 

Convert Date to string in _parse() Method


Output
“2012-03-16”

 

Adding Time Zone in Ruby _parse() Method

Output
{:zone=>"GMT", :hour=>2, :min=>30, :year=>2012, :mon=>3, :mday=>16, :offset=>0}

 

Adding Days in _parse() Method


Output
2012-03-21

 

Substracting Days in _parse() Method

Output
2012-03-11

 

LearnAndLearn.com © 2018 - All rights reserved