Post Reply 
(12C) Gregorian Date to Julian Day Number and vice versa
01-14-2019, 09:28 PM
Post: #7
RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01-14-2019 06:27 PM)Albert Chan Wrote:  I thought so too, until I tried Julian Day Number Calculator.

From the sources:
Code:
<!-- This is what an HTML comment looks like (This line terminates HTML comment) -->

Good to know. This gave me a chuckle.
And the fact that the page was was last modified on 980126.
Will we eventually find a Y2K bug?

The algorithm is described on a related page:
Quote:It is easy (with your calculator) to calculate the Julian Day Number of any date given on the Gregorian Calendar. The Julian Day Number so calculated will be for 0 hours, GMT, on that date. Here's how to do it:

1) Express the date as Y M D, where Y is the year, M is the month number (Jan = 1, Feb = 2, etc.), and D is the day in the month.

2) If the month is January or February, subtract 1 from the year to get a new Y, and add 12 to the month to get a new M. (Thus, we are thinking of January and February as being the 13th and 14th month of the previous year).

3) Dropping the fractional part of all results of all multiplications and divisions, let

A = Y/100
B = A/4
C = 2-A+B
E = 365.25x(Y+4716)
F = 30.6001x(M+1)
JD= C+D+E+F-1524.5

This is the Julian Day Number for the beginning of the date in question at 0 hours, Greenwich time. Note that this always gives you a half day extra. That is because the Julian Day begins at noon, Greenwich time. This is convenient for astronomers (who until recently only observed at night), but it is confusing.

But this appears to be what's calculated in the JavaScript sources:
Code:
    if(M<3)    {
        Y--;
        M += 12;
    }

//alert("D= " + D);
//alert("M= " + M);
//alert("Y= " + Y);
    if(document.forms[0].calendar[0].checked == true)    {
        var A = Math.floor(Y/100);
        var B = Math.floor(A/4);
        var C = 2 - A + B;
    }
    else
        C=0;
//alert("C= " + C);
    var E = Math.floor(365.25*(Y + 4716));
//alert("E= " + E);
    var F = Math.floor(30.6001*(M + 1));
//alert("F= " + F);
    var julianday = C + eval(D) + E + F - 1524.5;

Which appears to be consistent with Dieter's link to Wikipedia:
Quote:wenn Monat > 2 dann Y = Jahr, M = Monat
sonst Y = Jahr-1, M = Monat+12

D = Tag

H = Stunde/24 + Minute/1440 + Sekunde/86400

wenn TT.MM.YYYY >= 15.10.1582
dann gregorianischer Kalender: A = Int(Y/100), B = 2 - A + Int(A/4)

wenn TT.MM.YYYY <= 04.10.1582
dann julianischer Kalender: B = 0

sonst Fehler: Das Datum zwischen dem 04.10.1582 und dem 15.10.1582 existiert nicht.
Auf den 04.10.1582 (julianischer Kalender) folgte
unmittelbar der 15.10.1582 (gregorianischer Kalender).

JD = Int(365,25*(Y+4716)) + Int(30,6001*(M+1)) + D + H + B - 1524,5
Except that the variable H for hours is missing.

And that's what I got for 2000-01-01 using Python:
Code:
>>> Y, M, D = 2000 - 1, 1 + 12, 1
>>> A = Y/100
>>> B = A/4
>>> C = 2-A+B
>>> E = int(365.25 * (Y+4716))
>>> F = int(30.6001*(M+1))
>>> JD= C+D+E+F-1524.5
>>> JD
2451544.5

But I have to admit that I still don't really understand the difference between Julian Date and Julian Day Number.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (12C) Gregorian Date to Julian Day Number and vice versa - Thomas Klemm - 01-14-2019 09:28 PM



User(s) browsing this thread: 1 Guest(s)