Pregunta

Here's an PHP example to go from Julian date to Gregorian date:

$jd = gregoriantojd(10,3,1975);
echo($jd . "<br />");

$gregorian = jdtogregorian($jd);
echo($gregorian);

Output:
2442689
10/3/1975

This works if you have the full Julian date, but what if you only have a Julian day like '254' and the year '2012'? How do you get to a Gregorian date with just the Julian day and Gregorian year with PHP?

Here's a graph of Julian days:

http://landweb.nascom.nasa.gov/browse/calendar.html

Is this possible with PHP?

Edit: Based on the answers, here's what I came up with, although there may be an easier way:

$JulianDay = 77;
$Year = 1977;
$DateYear = date("Y/m/d", mktime(0, 0, 0, 1, 1, $Year));
$GregDate = new DateTime($DateYear);
$GregDate->modify("+$JulianDay day");
$Date = $GregDate->format('Y/m/d');
echo $Date; // '1977/03/19'
¿Fue útil?

Solución

echo jdtogregorian(gregoriantojd(01, 01, 2012)+253);

If 254 in 2012 is September 10 (it seems like it from your link) it works fine.

Otros consejos

$date = strtotime('+'.YourDay.' days', mktime(0, 0, 0, 0, 0, YourYear));

strtotime is and incredible function

You can use below function in php to do the same.

function d2julian($indate) {
    $year = ltrim(date('y', $indate),'0');     /* Year part with leading zeroes stripped    */
    if ($year == 0) $outdate = '00';
    else if ($year < 10) $outdate = '0' . $year;
    else $outdate = $year;

    $day = ltrim(date('z',$indate)+1,'0');    /* Day with leading zeroes stripped            */
    if ($day < 10) $outdate .= '00' . $day;
    else if ($day < 100) $outdate .= '0' . $day;
    else $outdate .= $day;

    return $outdate;
}

Hope this helps. Let me know in case you have any questions.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top