PHP 8.4.0 RC4 available for testing

jdtounix

(PHP 4, PHP 5, PHP 7, PHP 8)

jdtounix将儒略日数转换为 Unix 时间戳

说明

jdtounix(int $julian_day): int

这个函数将返回与 julian_day 给出的儒略日相对应的 Unix 时间戳。返回的时间是 UTC。

参数

julian_day

儒略日数在 64 位系统上是 2440588106751993607888 之间的数字,在 32 位系统上是 24405882465443 之间的数字。

返回值

指定儒略日的开始时(午夜,而非中午)的 unix 时间戳。

错误/异常

julian_day 超出允许的范围值,抛出 ValueError

更新日志

版本 说明
8.0.0 此函数在失败时不再返回 false,而是引发 ValueError
7.3.24, 7.4.12 扩充了 julian_day 的上限。以前无论计算机体系结构如何,都是 2465342

参见

  • unixtojd() - 将 Unix 时间戳转换为儒略日数

添加备注

用户贡献的备注 5 notes

up
6
fabio at llgp dot org
18 years ago
If you need an easy way to convert a decimal julian day to an unix timestamp you can use:

$unixTimeStamp = ($julianDay - 2440587.5) * 86400;

2440587.5 is the julian day at 1/1/1970 0:00 UTC
86400 is the number of seconds in a day
up
3
Anonymous
19 years ago
Warning: the calender functions involving julian day operations seem to ignore the decimal part of the julian day count.

This means that the returned date is wrong 50% of the time, since a julian day starts at decimal .5 . Take care!!
up
0
seb at carbonauts dot com
21 years ago
Remember that unixtojd() assumes your timestamp is in GMT, but jdtounix() returns a timestamp in localtime.

This fooled me a few times.

So if you have:

$timestamp1 = time();
$timestamp2 = jdtounix(unixtojd($timestamp1));

Unless your localtime is the same as GMT, $timestamp1 will not equal $timestamp2.
up
-1
pipian at pipian dot com
21 years ago
Remember that UNIX timestamps indicate a number of seconds from midnight of January 1, 1970 on the Gregorian calendar, not the Julian Calendar.
up
-2
Saeed Hubaishan
10 years ago
unixtojd() assumes that your timestamp is in GMT, but jdtounix() returns a timestamp in localtime.
so
<?php
$d1
=jdtogregorian(unixtojd(time()));
$d2= gmdate("m/d/Y");
$d3=date("m/d/Y");
?>
$d1 always equals $d2 but $d1 may differ from $d3
To Top