Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While the method </p> <pre><code>public static double ToJulianDate(this DateTime date) { return date.ToOADate() + 2415018.5; } </code></pre> <p>works for modern dates, it has significant shortcomings. </p> <p>The Julian date is defined for negative dates - i.e, BCE (before common era) dates and is common in astronomical calculations. You cannot construct a DateTime object with the year less than 0, and so the Julian Date cannot be computed for BCE dates using the above method.</p> <p>The Gregorian calendar reform of 1582 put an 11 day hole in the calendar between October 4th and the 15th. Those dates are not defined in either the Julian calendar or the Gregorian calendar, but DateTime accepts them as arguments. Furthermore, using the above method does not return the correct value for any Julian date. Experiments with using the System.Globalization.JulianCalendar.ToDateTime(), or passing the JulianCalendar era into the DateTime constructor still produce incorrect results for all dates prior to October 5, 1582. </p> <p>The following routines, adapted from Jean Meeus' "Astronomical Algorithms", returns correct results for all dates starting from noon on January 1st, -4712, time zero on the Julian calendar. They also throw an ArgumentOutOfRangeException if an invalid date is passed. </p> <pre><code> public class JulianDate { public static bool isJulianDate(int year, int month, int day) { // All dates prior to 1582 are in the Julian calendar if (year &lt; 1582) return true; // All dates after 1582 are in the Gregorian calendar else if (year &gt; 1582) return false; else { // If 1582, check before October 4 (Julian) or after October 15 (Gregorian) if (month &lt; 10) return true; else if (month &gt; 10) return false; else { if (day &lt; 5) return true; else if (day &gt; 14) return false; else // Any date in the range 10/5/1582 to 10/14/1582 is invalid throw new ArgumentOutOfRangeException( "This date is not valid as it does not exist in either the Julian or the Gregorian calendars."); } } } static private double DateToJD(int year, int month, int day, int hour, int minute, int second, int millisecond) { // Determine correct calendar based on date bool JulianCalendar = isJulianDate(year, month, day); int M = month &gt; 2 ? month : month + 12; int Y = month &gt; 2 ? year : year - 1; double D = day + hour/24.0 + minute/1440.0 + (second + millisecond / 1000.0)/86400.0; int B = JulianCalendar ? 0 : 2 - Y/100 + Y/100/4; return (int) (365.25*(Y + 4716)) + (int) (30.6001*(M + 1)) + D + B - 1524.5; } static public double JD(int year, int month, int day, int hour, int minute, int second, int millisecond) { return DateToJD(year, month, day, hour, minute, second, millisecond); } static public double JD(DateTime date) { return DateToJD(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Millisecond); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload