Learn and Learn

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

Ruby – Get the Julian Day Number – jd() Method – Examples & Explanation

In Ruby, the jd() method generates a date object indicating the given chronological Julian day number. To get the chronological Julian day number, use Date.jd() method.

jd() Method in Ruby

jd() method exists in Standard Date Library of Ruby. The purpose of this method is to generate a date object indicating the given chronological Julian day number.


Syntax of the jd() Method in Ruby

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


Parameter of jd() Method in Ruby

x is any valid Julian date object. This parameter is required.
Note: If the x parameter is not a valid Julian date object jd() method will return an error and if it is zero, it will show the start of the calendar like -4712-01-01.


Return Value of jd() Method

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


Julian Date Format

The date format for Julian (JUL) is CYYDDD.
Here YY represents the year and the DDD indicates the day of the year.


How to Get the Julian Day Number in Ruby?




Note: In the above code (0) represents the start of the Julian Calendar Date as given in the output.


How to convert Julian Date to Calendar Date?

To covert the Julian date to current Calendar Date see the following example.


NOTE: In the above code (14125), 14 represent the year and 125 is represents the day of the year.


How to Convert Current Date and Time into Julian Date Number?


NOTE: The amjd() function is used to convert the current date into Julian date and then converting the output into float is helpful to understand easy.


LearnAndLearn.com © 2018 - All rights reserved