linux php jdtogregorian 开启,PHP unixtojd()用法及代码示例

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值