unixtojd()是PHP中的内置函数,可将unix时间戳转换为儒略日计数。 UNIX时间戳是一种跟踪时间(以秒为单位)的方式。此计数从1970年1月1日UTC的Unix Epoch开始。因此,UNIX时间戳只是特定日期和Unix纪元之间的秒数。
用法:
unixtojd( $unix )
参数:该函数接受如上所示的单个参数,该参数是可选的。 $unix指定将unix时间戳转换为儒略日计数。
返回值:该函数返回作为参数传递的unix时间戳,该时间戳转换为Julian day Integer。如果未传递任何参数,则返回当前的儒略日整数。我们可以使用jdtogregorian()函数将儒略日整数转换为公历日期,以了解确切日期。
例子:
Input : $unix = 1524909427
Output : 2458237
Explanation: The Gregorian date is 4/28/2018 of
the given unix timestamp
Input : $unix = 5677896
Output : 2440653
Explanation: The Gregorian date is 3/7/1970 of
the given unix timestamp
注意:该函数只能使用儒略日整数,直到公历日期1/19/2038,因为在该日期Unix时间戳由于32位溢出而停止工作。
以下示例程序旨在说明unixtojd()函数。
程序1:下面的程序演示了不传递任何参数时函数的用法。
// PHP program to demonstrate the use of unixtojd()
// function when no parameter is passed
// takes the current date as unix timestamp
$jd = unixtojd();
// prints the julian Day integer
echo "The Julian Day integer is ", ($jd), "\n";
// prints the corresponding Gregorian date
echo "The Gregorian date is ", jdtogregorian($jd);
?>
输出:
The Julian Day integer is 2458237
The Gregorian date is 4/28/2018
程序2:下面的程序演示了传递参数时函数的使用。
// PHP program to demonstrate the use of unixtojd()
// function when parameter is passed
// takes a unix timestamp in parameter
$jd = unixtojd(5677896);
// prints the julian Day integer
echo "The Julian Day integer is ", ($jd), "\n";
// prints the corresponding Gregorian date
echo "The Gregorian date is ", jdtogregorian($jd);
?>
输出:
The Julian Day integer is 2440653
The Gregorian date is 3/7/1970