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.