PHP - juliantojd() 函式



PHP 日曆 **juliantojd()** 函式用於將儒略曆日期轉換為儒略日數。儒略曆的有效範圍為公元前 4713 年到公元 9999 年。

語法

以下是 PHP 日曆 **juliantojd()** 函式的語法:

int juliantojd ( int $month, int $day, int $year )

引數

以下是 **juliantojd()** 函式的引數:

  • **$month** - 月份,數字 1 到 12。

  • **$day** - 日期,數字 1 到 31。

  • **$year** - 年份,數字 -4713 到 9999。

返回值

**juliantojd()** 函式返回給定儒略曆日期的儒略日數,這是一個整數。

PHP 版本

**juliantojd()** 函式首次出現在 PHP 4 的核心程式碼中,並在 PHP 5、PHP 7 和 PHP 8 中繼續正常工作。

示例 1

這是一個 PHP 日曆 **juliantojd()** 函式的基本示例,用於將儒略曆日期轉換為儒略日數。

<?php
   // Mention the julian date
   $jd = juliantojd(10, 3, 2007);
   echo($jd . "\n");
   
   $julian = jdtojulian($jd);
   echo($julian);
?>

輸出

以下是這段程式碼的輸出:

2454390
10/3/2007

示例 2

此示例使用 **juliantojd()** 函式計算兩個儒略曆日期之間的天數差。

<?php
   // Mention the julian dates here
   $jd = juliantojd(1, 1, 1600);
   $jd2 = juliantojd(1, 1, 1700);

   // Calculate the difference
   $difference = $jd2 - $jd;

   // Display the result
   echo "Difference in days between January 1, 1600 and January 1, 1700: " . $difference;
?> 

輸出

這將生成以下輸出:

Difference in days between January 1, 1600 and January 1, 1700: 36525

示例 3

此示例使用 PHP 的內建方法 **juliantojd()** 函式來確定當前日期的儒略日數。

<?php
   $month = date("n");
   $day = date("j");
   $year = date("Y");
   $jd = juliantojd($month, $day, $year);
   echo "Julian Day Count for today (" . date("F j, Y") . "): " . $jd;
?> 

輸出

這將建立以下輸出:

Julian Day Count for today (August 16, 2024): 246055

示例 4

在以下示例中,我們使用使用者定義函式 convertToJulianDay() 來轉換給定的儒略曆日期為其儒略日數,使用 **juliantojd()** 函式。

<?php
   // User-defined function 
   function convertToJulianDay($month, $day, $year) {
      return juliantojd($month, $day, $year);
   }
   
   // Usage of the function
   $month = 7;
   $day = 20;
   $year = 1969;
   $jd = convertToJulianDay($month, $day, $year);
   
   echo "Julian Day Count for July 20, 1969: " . $jd;
?> 

輸出

以下是上述程式碼的輸出:

Julian Day Count for July 20, 1969: 2440436
php_function_reference.htm
廣告