PHP - Calendar frenchtojd() 函式



PHP Calendar **frenchtojd()** 函式用於將日期從法國共和曆轉換為儒略日數。儒略日計數是從公元前4713年1月1日開始的無限天數計數。此函式使處理法國共和曆中的歷史日期更加容易。

語法

以下是 PHP Calendar **frenchtojd()** 函式的語法:

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

引數

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

  • **$month** - 月份,數值為 1 到 13。

  • **$day** - 日期,數值為 1 到 30。

  • **$year** - 年份,數值為 1 到 14。

返回值

**frenchtojd()** 函式返回給定法國革命日期的儒略日數,以整數形式表示。

PHP 版本

**frenchtojd()** 函式最早在 PHP 4 核心版本中引入,並在 PHP 5、PHP 7 和 PHP 8 中都能正常工作。

示例 1

以下是 PHP Calendar **frenchtojd()** 函式的基本示例,用於將法國共和曆日期轉換為儒略日。

<?php
   // 1st day of the 1st month in the 1st year
   $jd = frenchtojd(1, 1, 1); 

   // Output the result
   echo $jd;
?>

輸出

以下是程式碼的輸出:

2375840

示例 2

在下面的 PHP 程式碼中,我們將嘗試使用 **frenchtojd()** 函式轉換年中某個日期。

<?php
   // 15th day of the 7th month in the 2nd year
   $jd = frenchtojd(7, 15, 2); 

   // Output the result
   echo $jd;
?> 

輸出

這將生成以下輸出:

2376139

示例 3

下面的程式碼使用 **frenchtojd()** 函式轉換法國共和曆年末的日期,並打印出來。

<?php
   // 30th day of the 12th month in the 3rd year
   $jd = frenchtojd(12, 30, 3); 

   // Output the result
   echo $jd;
?>

輸出

這將生成以下輸出:

2376434

示例 4

在下面的示例中,我們使用 **frenchtojd()** 函式轉換法國共和曆閏年中的日期。

<?php
   // 1st day of the 13th month (leap year) in the 4th year
   $jd = frenchtojd(13, 1, 4); 

   // Output the result
   echo $jd;
?> 

輸出

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

2376506

示例 5

這是一個將日期從法國曆轉換為儒略日的 PHP 程式碼示例。

<?php
   //  3rd day of the 3rd month in the 14th year
   $d = frenchtojd(3, 3, 14);

   // Output the result
   echo($d);
?> 

輸出

這將產生以下結果:

2380650
php_function_reference.htm
廣告
© . All rights reserved.