Learn and Learn

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

Ruby – Set the ISO8601 Format – iso8601() Method – Examples & Explanation

In Ruby, the iso8601() method generates a new date object by indicating from a string given in a code. Use Date.iso8601() to get the desired results.

iso8601() Method in Ruby

iso8601() method exists in Standard Date Library of Ruby. The purpose of this method is to generate a new date object by indicating from a string given in a code.

 

Syntax of the iso8601() Method in Ruby

In date, the syntax of iso8601() method is:

 

Parameter of iso8601() Method in Ruby

x is any valid date object in the form of string. This parameter is required.Note: If the x parameter is not a valid date object in form of a string or if it is zero, iso8601() method will return an error.

 

Return Value of iso8601()

iso8601() method generates a new date object by indicating from a string given in a code.

 

How to Get the Date in iso8601() Method?


Output
2015-05-10

 

See another Example


Output
2015-05-10

 

Ruby – Get wyear (Week of Year) and wday (Week Day) in iso8601() Method


Output
2015-02-24

NOTE: In the above code (‘2015-W09-2’), according to iso8601() format W09 represents the week of the year and 2 indicates the day of that week.

 

See another Example


Output
2015-04-09

NOTE: In the above code (‘2015-W15-4’), according to iso8601() format W15 represents the week of the year and 2 indicates the day of that week.

 

LearnAndLearn.com © 2018 - All rights reserved