PHP - 日曆 jdtogregorian() 函式



PHP 日曆 jdtogregorian() 函式用於將儒略日數轉換為包含格里高利日期的字串,格式為“月/日/年”。當您想要將儒略日期更改為格里高利曆日期時,此函式非常有用。

語法

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

string jdtogregorian ( $jd );

引數

此函式接受 $jd 引數,該引數是作為整數的儒略日數。

返回值

jdtogregorian() 函式以“月/日/年”的形式返回格里高利日期作為字串。

PHP 版本

jdtogregorian() 函式首次引入核心 PHP 4,在 PHP 5、PHP 7 和 PHP 8 中繼續輕鬆執行。

示例 1

首先,我們將向您展示 PHP 日曆 jdtogregorian() 函式的基本示例,以將單個儒略日數轉換為匹配的格里高利日期。

<?php
   // Julian day for January 1, 2000
   $jd = 2451545; 
   
   // Convert the gregorian date to Julian Day
   $gregorian_date = jdtogregorian($jd);
   
   // Display the result
   echo "The Gregorian Date: ".$gregorian_date; 
?>

輸出

以下是以下程式碼的結果:

The Gregorian Date: 01/01/2000

示例 2

在下面的 PHP 程式碼中,我們將使用 jdtogregorian() 函式,並展示如何將今天的日期從儒略日轉換為格里高利日期。

<?php
   // Convert Julian Date to Gregorian date
   $jd = gregoriantojd(8, 14, 2024); 

   // Convert the gregorian date to Julian Day
   $gregorian_date = jdtogregorian($jd);

   // Display the result
   echo $gregorian_date; 
?> 

輸出

這將生成以下輸出:

The Gregorian Date: 08/14/2024

示例 3

這是使用 jdtogregorian() 函式將歷史儒略日更改為格里高利日期的示例。

<?php
   // Julian day before the Gregorian calendar reform
   $julian_day = 2299161; 

   // Convert the gregorian date to Julian Day
   $gregorian_date = jdtogregorian($julian_day);

   // Display the result
   echo $gregorian_date; 
?> 

輸出

這將建立以下輸出:

The Gregorian Date: 10/15/1582

示例 4

這是一個示例,其中我們使用 jdtogregorian() 和 gregoriantojd() 函式將儒略日轉換為格里高利日,反之亦然,用於同一日期。

<?php
   // Julian day before the Gregorian calendar reform
   $jd = gregoriantojd(1, 12, 1990);
   echo "Here is the Julian Day - $jd \n";
   
   $gregorian = jdtogregorian($jd);
   echo "Here is the Gregorian Day - $gregorian \n";
?> 

輸出

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

Here is the Julian Day - 2447904 
Here is the Gregorian Day - 1/12/1990 
php_function_reference.htm
廣告