Ruby – Set jisx0301 Date Format – jisx0301() Method – Examples & Explanation

The jisx0301 method generates a new Date object by explaining from a string given in a code according to some typical JISX 0301 formats.

jisx0301() Method in Ruby

jisx0301() method exists in Standard Date Library of Ruby. The purpose of this method is to generates a new Date object by explaining from a string given in a code

 

Syntax of the jisx0301() Method in Ruby

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

Date.jisx0301(x)

 

Parameter of jisx0301() Method in Ruby

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

 

Return Value of jisx0301()

jisx0301() method will return a new Date object by explaining from a string given in a code.

 

Explaining jisx0301() Year format

The jisx0301() year format is start with a ‘H10’ which represents the year 01-01-1998 and is continue to ‘H99’ which represents the year 12-31-2087. The notable thing is the ‘H’ in this format is not case sensitive.

 

Ruby jisx0301() Example 1

# import date library
require 'date'
x = Date.jisx0301('H27.01.01')
puts x

Output
2015-01-01

 

Ruby jisx0301() Example 2

# import date library
require 'date'
x = Date.jisx0301('H28.12.31')
puts x

Output
2016-12-31

 

Ruby jisx0301() Example 3

# import date library
require 'date'
x = Date.jisx0301('H35.11.21')
puts x

Output
2023-11-21

 

Ruby jisx0301() Example 4

# import date library
require 'date'
x = Date.jisx0301('H40.11.21')
puts x

Output
2028-11-21