Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Algorithm Implementation/Date and time/Conversion of a Gregorian date to a Julian date

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

This provides various algorithms for converting a Gregorian calendar date into a Julian date. Fliegel and Van Flandern (1968) algorithm This Visual Basic version implements the Fliegel & Van Flandern (1968) algorithm for the conversion of Gregorian calendar dates to the Julian Day Number, reprinted in Explanatory Supplement to the Astronomical Almanac (1992), 2nd printing, edited by P. Kenneth Seidelmann, University Books, p. 604. This is an integer algorithm and computes only the Julian Day Number. To compute the Julian date, the fraction of the day since the instant of time noon on the given calendar date, Universal Time (-0.5 to 0.5) must be added. Note that the division here is integer truncating division - that is, 1 \ 2 = 0 and -1 \ 2 = 0. Function G2JD(y As Long, M As Long, D As Long) As Variant 'Given a year, month, and day of the Gregorian calendar 'find the corresponding Julian Day Number. 'Only valid for dates on or after JD 0 If y >= -4713 Then G2JD = (1461 * (y + 4800 + (M - 14) \ 12)) \ 4 _ + (367 * (M - 2 - 12 * ((M - 14) \ 12))) \ 12 _ - (3 * ((y + 4900 + (M - 14) \ 12) \ 100)) \ 4 + D - 32075 Else G2JD = CVErr(xlErrNum) End If End Function Tantzen (1969) algorithm For C/C++, originally written in Algol 60. int dateToJulian(int y, int m, int d) { // shift February to end of year if (m > 2) { m = m - 3; } else { m = m + 9; y = y - 1; } int c = y / 100; // century int ya = y - 100 * c; return (146097 * c) / 4 + (1461 * ya) / 4 + (153 * m + 2) / 5 + d + 1721119; } Meeus (1977) algorithm This was first published in French in Jour Julien et date du calendrier (1977) and later in many publications such as Astronomical Formulae for Calculators. Suitable for C/C++. double convertToJulianDate((int year, int month, double day) { // Adjust year and month when month is January or February. if (month <= 2) { year = year - 1; month = month + 12; } // Initialize the Gregorian calendar adjustment variable. double B = 0.0; // Check if the date is in the Gregorian calendar (after 1582-Oct-15). // The conditional handles the year, then the month, then the specific day. if (year > 1582 || (year == 1582 && (month > 10 || (month == 10 && day >= 15)))) { // Calculate the Gregorian calendar adjustment values A and B. // C's integer division automatically truncates the result, as required by the algorithm. int A = year / 100; B = 2.0 - A + (A / 4); } // Calculate the Julian Date using the provided formula. // The integer division (truncation) is handled by the `(int)` cast. return (int)(365.25 * year) + (int)(30.6001 * (month + 1)) + day + 1720994.5 + B; } Muller and Wimberly (1979) algorithm According to Flandern and Pulkkine 1979, P. M. Muller and R. N. Wimberly of the Jet Propulsion Laboratory improved Fliegel and Van Flandern's algorithm to this more compact form. Suitable for C/C++ and Fortran due to division rounding towards zero. JD = 367*Y - 7*(Y+(M+9)/12)/4 - 3*((Y+(M-9)/7)/100+1)/4 + 275*M/9 + D + 1721029 Montenbruck (1989) algorithm This Python version is based on Practical ephemeris calculations, Oliver Montenbruck, 1989. It uses floating-point operations. import math def get_julian_date(Y, M, D, UT): """ Calculates the Julian Date for a given Gregorian date and time. Args: Y (int): The year (e.g., 2025). M (int): The month (1-12). D (int): The day of the month (1-31). UT (float): Universal Time (decimal hours, 0.0 to 24.0). Returns: float: The calculated Julian Date. """ # 1. Calculate February-shifted quantities y and m (y,m) = (Y - 1, M + 12) if M <= 2 else (Y,M) # 2. Calculate B based on the date if Y < 1582 or (Y == 1582 and M < 10) or (Y == 1582 and M == 10 and D <= 4): # Applies up to and including Oct 4, 1582 (Julian calendar) B = -2 else: # Applies from and including Oct 15, 1582 (Gregorian calendar) B = math.floor(y / 400) - math.floor(y / 100) # 3. Calculate the Julian Date JD = ( math.floor(365.25 * y) + math.floor(30.6001 * (m + 1)) + B + 1720996.5 + D + UT / 24 ) return JD Calendrical Calculations algorithm This is based on computing jd-from-fixed(fixed-from-gregorian(ymd)) from the book Calendrical Calculations: The Ultimate Edition (2018). Javascript. function gregorianToJd(year, month, day) { const isLeap = (year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0); let fixedDate = (365 * (year - 1)) + Math.floor((year - 1) / 4) - Math.floor((year - 1) / 100) + Math.floor((year - 1) / 400) + Math.floor((367 * month - 362) / 12) + // Correction for length of February ((month > 2) ? (isLeap ? -1 : -2) : 0) + day return fixedDate + 1721424.5; // see gregorian-epoch and jd-epoch }