As an exercise, I am trying to calculate the JD from a given date in the Gregorian Calendar at a time given in UT. Furthermore, I want to do so from first principles without relying on any formula. Let's say I choose UT 18:30 on 2/28/2010. I am not able to obtain a result consistent with the U.S. Naval Observatory results. I am in need of a calendar guru to show me where my calculation is going astray.
First I find the number of years from 4713 BCE (Julian Date 0) and the target year making sure to add an extra one so as to include 0 CE. This is $4713 + 1 + 2010 = 6724$ years. The number of these years which are leap is $\frac{6724}{4} - 3 = 1681$. This equation attempts to reflect that every fourth year is a leap year except for those years falling after 1582 (the year of the Gregorian Calendar reform) which are both divisible by $100$ and not by $400$. There are three such years which need to be deducted from the total-- 1700, 1800, 1900. This leaves $6724 - 1681 = 5043$ non-leap years.
Now I convert these to days and subtract the $10$ days which were skipped as part of the reform from October 4 to October 15 in 1582. $5043*(365) + 1681*(366) - 10 = 2,455,928$. Next, I find the number of days from January 1st to the target day in the target year (February 28th). This is $59$ days and so I have $2,455,987$.
Finally, the time number of seconds afternoon on the target day is calculated as a fraction of the number of seconds in a 24 hour period. This works out to be $\frac{6(60)(60) + 30(60)}{24(60)(60)} \approx 0.27$. Adding this to the earlier result yields $JD = 2455987.27$.
The actual answer is $2455255.77$ which leaves a difference of $2455987.27 - 2455255.77 = 731.5$ days. This is nearly two years. Obviously, I have either misunderstood the calculation or have performed it incorrectly. Any help would be much appreciated!