Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP - Calendar jdtojulian() Function



The PHP Calendar jdtojulian() function is used to convert Julian Day Count to a string containing the Julian Calendar Date in the format of "month/day/year".

Syntax

Below is the syntax of the PHP Calendar jdtojulian() function −

string jdtojulian ( int $jd )

Parameters

This function accepts $jd parameter which is a julian day number as integer.

Return Value

The jdtojulian() function returns a string containing the Julian calendar date in the format "month/day/year".

PHP Version

First introduced in core PHP 4, the jdtojulian() function continues to function easily in PHP 5, PHP 7, and PHP 8.

Example 1

Here is the basic example of the PHP Calendar jdtojulian() function to convert the julian ay count to a julian calendar date.

<?php
   // Julian Day Count
   $jdc = 2451545

   // Conversion to julian calendar date
   $julianDate = jdtojulian($jdc);

   // Display the result
   echo $julianDate;
?>

Output

Here is the outcome of the following code −

12/19/1999

Example 2

In this example, we create a simple function to convert a Julian day count to a Julian calendar date by using the jdtojulian() function.

<?php
   // Define the function here
   function convertToJulian($julianDayCount) {
      return jdtojulian($julianDayCount);
   }
  
   $julianDate = convertToJulian(2451545);
   echo $julianDate;
?> 

Output

This will generate the below output −

12/19/1999

Example 3

This example shows how to use the conversion logic inside a class for better management. The JulianConverter class has a method convert(), which accepts the Julian day count and returns its Julian date.

<?php
   // Define class here
   class JulianConverter {
      public function convert($julianDayCount) {
          return jdtojulian($julianDayCount);
      }
   }
  
   $converter = new JulianConverter();
   $julianDate = $converter->convert(2299160);
   echo $julianDate;
?> 

Output

This will create the below output −

10/4/1582

Example 4

In the following example, we will demonstrates how multiple instances of a class can be used to perform different conversions.

<?php
   // Define class here
   class JulianConverter {
      public function convert($julianDayCount) {
          return jdtojulian($julianDayCount);
      }
   }
   
   $converter1 = new JulianConverter();
   $converter2 = new JulianConverter();
   
   $julianDate1 = $converter1->convert(3000000);
   $julianDate2 = $converter2->convert(2450000);
   
   echo "Date for 3000000: " . $julianDate1 . "\n";
   echo "Date for 2450000: " . $julianDate2;
?> 

Output

Following is the output of the above code −

Date for 3000000: 7/21/3501
Date for 2450000: 9/26/1995
php_function_reference.htm
Advertisements