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(PHP 4, PHP 5, PHP 7, PHP 8)
jdtounix β ΠΠ΅ΡΠ΅Π²ΠΎΠ΄ΠΈΡ ΡΠΈΡΠ»ΠΎ Π΄Π½Π΅ΠΉ Π² ΡΠ»ΠΈΠ°Π½ΡΠΊΠΎΠΌ Π»Π΅ΡΠΎΠΈΡΡΠΈΡΠ»Π΅Π½ΠΈΠΈ Π² ΠΌΠ΅ΡΠΊΡ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ Unix
ΠΡΠ° ΡΡΠ½ΠΊΡΠΈΡ Π²Π΅ΡΠ½ΡΡ ΠΌΠ΅ΡΠΊΡ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ Unix, ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΡΡ Π½ΠΎΠΌΠ΅ΡΡ Π΄Π½Ρ Π²
ΡΠ»ΠΈΠ°Π½ΡΠΊΠΎΠΌ Π»Π΅ΡΠΎΠΈΡΡΠΈΡΠ»Π΅Π½ΠΈΠΈ, Π·Π°Π΄Π°Π½Π½ΠΎΠΌΡ Π² julian_day. ΠΡΠ΄Π΅Ρ Π²ΠΎΠ·Π²ΡΠ°ΡΠ΅Π½ΠΎ UTC.
julian_day
ΠΠΎΠΌΠ΅Ρ Π΄Π½Ρ Π² ΡΠ»ΠΈΠ°Π½ΡΠΊΠΎΠΌ Π»Π΅ΡΠΎΠΈΡΡΠΈΡΠ»Π΅Π½ΠΈΠΈ ΠΌΠ΅ΠΆΠ΄Ρ 2440588 ΠΈ 106751993607888
Π² 64-Π±ΠΈΡΠ½ΡΡ
ΡΠΈΡΡΠ΅ΠΌΠ°Ρ
ΠΈΠ»ΠΈ ΠΌΠ΅ΠΆΠ΄Ρ 2440588 ΠΈ 2465443 Π² 32-Π±ΠΈΡΠ½ΡΡ
ΡΠΈΡΡΠ΅ΠΌΠ°Ρ
.
ΠΠ΅ΡΠΊΠ° Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ Unix Π½Π° ΠΌΠΎΠΌΠ΅Π½Ρ Π½Π°ΡΠ°Π»Π° (ΠΏΠΎΠ»Π½ΠΎΡΡ) ΡΠ»ΠΈΠ°Π½ΡΠΊΠΎΠ³ΠΎ Π΄Π½Ρ.
ΠΡΠ»ΠΈ julian_day Π½Π°Ρ
ΠΎΠ΄ΠΈΡΡΡ Π·Π° ΠΏΡΠ΅Π΄Π΅Π»Π°ΠΌΠΈ Π΄ΠΎΠΏΡΡΡΠΈΠΌΠΎΠ³ΠΎ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½Π°,
Π²ΡΠ±ΡΠ°ΡΡΠ²Π°Π΅ΡΡΡ ValueError.
| ΠΠ΅ΡΡΠΈΡ | ΠΠΏΠΈΡΠ°Π½ΠΈΠ΅ |
|---|---|
| 8.0.0 |
Π€ΡΠ½ΠΊΡΠΈΡ Π±ΠΎΠ»ΡΡΠ΅ Π½Π΅ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ false Π² ΡΠ»ΡΡΠ°Π΅ Π²ΠΎΠ·Π½ΠΈΠΊΠ½ΠΎΠ²Π΅Π½ΠΈΡ ΠΎΡΠΈΠ±ΠΊΠΈ,
Π²ΠΌΠ΅ΡΡΠΎ ΡΡΠΎΠ³ΠΎ Π²ΡΠ±ΡΠ°ΡΡΠ²Π°Π΅Ρ ValueError.
|
| 7.3.24, 7.4.12 |
Π£Π²Π΅Π»ΠΈΡΠ΅Π½ Π²Π΅ΡΡ
Π½ΠΈΠΉ ΠΏΡΠ΅Π΄Π΅Π» julian_day.
Π Π°Π½ΡΡΠ΅ ΠΎΠ½ Π±ΡΠ» 2465342 Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΠΎ ΠΎΡ Π°ΡΡ
ΠΈΡΠ΅ΠΊΡΡΡΡ.
|
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 dayWarning: 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!!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.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 $d3Remember that UNIX timestamps indicate a number of seconds from midnight of January 1, 1970 on the Gregorian calendar, not the Julian Calendar.