Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: unixtojd - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Date/Time" width="11" height="7"/> <カレンダー 関数
Last updated: Fri, 06 Jun 2008

view this page in

unixtojd

(PHP 4, PHP 5)

unixtojd — Unix タイムスタンプをユリウス歴に変換する

説明

int unixtojd ([ int $timestamp ] )

Unix タイムスタンプ(1970/1/1 からの秒数)timestamp をユリウス歴に変換して返します。timestamp が 指定されない場合は現在の日付が使用されます。

パラメータ

timestamp

変換したい Unix タイムスタンプ。

返り値

ユリウス積算日を表す整数値を返します。

参考



add a note add a note User Contributed Notes
unixtojd
hrabi at linuxwaves dot com
29-Mar-2007 11:02
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
29-Mar-2007 08:33
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
31-Aug-2006 06:09
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.
11-Aug-2006 11:22
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;
warhog at warhog d0t net
13-Jul-2005 06:11
Well, that's neither a bug, nor an interesting quirk.. The explanation is quite simple:

The Integer containing a julian date (jd) only stores the date, not the time. When you convert a unix-timestamp, which stores also the time, into a jd, the time-information won't be transferred into the jd. When converting back the jd into a unix-timestamp, you'll get a timestamp for the specific day at 2 o'clock am. ( 02:00:00 )

Sample:
    Timestamp: 1121206013
    JD: 2453565

    Timestamp from JD: 1121212800

    Original Timestamp "d.m.y H:i:s": 13.07.2005 00:06:53
    Timstamp from JD "d.m.y H:i:s": 13.07.2005 02:00:00

greetz
Mike
22-Dec-2004 01:57
Interesting quirk ... maybe bug.
If you use today = unixtojd(time())
then use jdtounix(today) the result is one day short of today.
johnston at capsaicin dot ca
20-Nov-2003 06:43
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
13-Jun-2003 01:29
Remember that UNIX timestamps indicate a number of seconds from midnight of January 1, 1970 on the Gregorian calendar, not the Julian Calendar.

 
show source | credits | sitemap | contact | advertising | mirror sites