PHP 日历函数

PHP jdtounix() 函数返回与 julian_day 中给定的儒略日相对应的 Unix 时间戳。返回的时间为 UTC。

注意:Unix 时间戳表示自 1970 年 1 月 1 日午夜(公历)以来的秒数。

语法

jdtounix(julian_day) 

参数

julian_day必填。 指定 64 位系统上 2440588 到 106751993607888 之间的儒略日数,或 32 位系统上 2440588 到 2465443 之间的儒略日数。

返回值

返回给定儒略日开始(午夜,而不是中午)的 unix 时间戳。

例外

如果 julian_day 超出了

示例:

下面的示例显示了jdtounix()函数的用法。

<?php
//转换公历日期
//转为儒略整数
$jd = gregoriantojd(10, 2, 2015);
  
//显示儒略日整数
echo "The Julian day integer is: $jd \n";
  
//转换儒略日整数
//转Unix时间戳
$date = jdtounix($jd);
  
//显示Unix时间戳
echo "The Unix timestamp is: $date \n"; 
?> 

上述代码的输出将是:

The Julian day integer is: 2457298 
The Unix timestamp is: 1443744000 

示例:溢出行为

再考虑一个示例来查看溢出行为

<?php
//转换公历日期
//转为儒略整数
$jd = gregoriantojd(10, 2, 1950);
  
//显示儒略日整数
echo "The Julian day integer is: $jd \n";
  
//转换儒略日整数
//转Unix时间戳
//作为$jd抛出ValueError
//超出允许范围
$date = jdtounix($jd);
  
//显示Unix时间戳
echo "The Unix timestamp is: $date \n"; 
?> 

上述代码的输出将是:

The Julian day integer is: 2433557 

PHP Fatal error:  Uncaught ValueError: jday must be between 2440588 and 106751993607888 in Main.php:13
Stack trace:
#0 Main.php(13): jdtounix()
#1 {main}
  thrown in Main.php on line 13