Calendar 函数
在线手册:中文  英文

unixtojd

(PHP 4, PHP 5)

unixtojd转变Unix时间戳为Julian Day计数

说明

int unixtojd ([ int $timestamp = time() ] )

根据指定的Unix时间戳timestamp,返回Julian天数。如果没有指定时间戳则返回当前日期的天数。

参数

timestamp

一个用于转变的时间戳。

返回值

一个julian天数。

参见


Calendar 函数
在线手册:中文  英文

用户评论:

Anonymous (2012-03-20 21:01:36)

Since upgrading from PHP 5.2.9 to 5.3.10, PHP is throwing the error:
... PHP Fatal error: Call to undefined function unixtojd() in .../unixtojd.php on line 5
Checking phpinfo(), I can see that the calendar lib is enabled:
'--enable-calendar=shared'
Searching on Google for posts since the first release of PHP 5.3 (June 30, 2009) did not reveal much more: http://goo.gl/2YbWj
If anyone has an answer, please notify me at lsiden at gmail since I have not found a way to get notified here.
Thank you!

hrabi at linuxwaves dot com (2007-03-29 06:02:07)

according to http://www.decimaltime.hynes.net/dates.html#jd and reading "X. Calendar Functions" on this side, it seems that php "jd" is precisely mean as "Chronological Julian Day" (should it be named cjd, and primarily strictly mentioned - isn't it?), used for covnersion between calendar systems. Than it's ok (but Incomplete manual is strongly confusing here IMHO).
Even that, cJD is adjusted to a local time, so... I am rather babeled now, so nothing else :-).

hrabi at linuxwaves dot com (2007-03-29 03:33:10)

This is unusable. Julian Day start at noon, not midnight. It's better to use Fabio solution (however there is a lurk problem with leap second).

<?php
function mmd($txt$str_time) {
   
$t strtotime($str_time);
   
$j unixtojd($t);
   
$s gmstrftime('%D %T %Z'$t);
   
$j_fabio $t 86400 2440587.5;

   
printf("${txt} => (%s) %s, %s U, %s J, or %s J<br>\n"$str_time$s$t$j$j_fabio);
}

//$xt = strtotime("1.1.1970 15:00.00 GMT");
$sam "9.10.1995 02:00.01 GMT";
$spm "9.10.1995 22:00.01 GMT";

// unixtojd for $spm returns 2450000 (OK), but for $sam returns 2450000 too! (it is wrong).
mmd("am"$sam);  // should be 2449999 (+ 0.58334)
mmd("pm"$spm);  // should be 2450000 (+ 0.41668)
?>

reference
unix time, and UTC, TAI, ntp, ... problems: http://en.wikipedia.org/wiki/Unix_time
Julian Date Converter: http://aa.usno.navy.mil/data/docs/JulianDate.html
history overview: http://parris.josh.com.au/humour/work/17Nov1858.shtml

fabio at llgp dot org (2006-08-31 02:09:57)

If you need an easy way to convert an unix timestamp to a decimal julian day you can use:
$julianDay = $unixTimeStamp / 86400 + 2440587.5;
86400 is the number of seconds in a day;
2440587.5 is the julian day at 1/1/1970 0:00 UTC.

(2006-08-10 19:22:42)

Its clearly stated that this function returns the Julian Day, not Julian Day + time.
If you want the time with it you will have to do something like:
$t=time();
$jd=unixtojd($t)+($t%60*60*24)/60*60*24;

johnston at capsaicin dot ca (2003-11-19 13:43:51)

Also note that epoch is in UTC time (epoch is a specific point in time - epoch is not different for every time zone), so be aware of timezone complexities.

pipian at pipian dot com (2003-06-12 09:29:31)

Remember that UNIX timestamps indicate a number of seconds from midnight of January 1, 1970 on the Gregorian calendar, not the Julian Calendar.

易百教程