The Julian day is the standard form of reporting the date in astronomy. One Julian day is equal to one normal day, with the fractional part being the time of day expressed as a fraction of a day.

The Julian day starts on 1st January 4713BC, at Greenwich noon. This means that the Julian day is offset from a normal day by half, with the day starting at noon.

The current value of the Julian day at the time of writing this tutorial is 2455117.64.

The algorithm for calculating the Julian day for Gregorian dates is
JD = (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

and converting Julian dates, the formula is
JD = 367 × Y − (7 × (Y + 5001 + (M − 9)/7))/4 + (275 × M)/9 + D + 1729777

We then have to add in the fractional time portion which is defined by
JD = JD + (hour – 12) / 24 + minute / 1440 + second / 86400.

The functions below also pass the time zone, thus converting the dates (in Local Zone Time) UT, and vice versa.

		public static double GetJulianDay(DateTime dDate, int iZone)
		{
			double fJD;
			double iYear;
			double iMonth;
			double iDay;
			double iHour;
			double iMinute;
			double iSecond;
			double iGreg;
			double fA;
			double fB;
			double fC;
			double fD;
			double fFrac;

			dDate = CalcUTFromZT(dDate, iZone);

			iYear = dDate.Year;
			iMonth = dDate.Month;
			iDay = dDate.Day;
			iHour = dDate.Hour;
			iMinute = dDate.Minute;
			iSecond = dDate.Second;
			fFrac = iDay + ((iHour + (iMinute / 60) + (iSecond / 60 / 60)) / 24);
			if (iYear < 1582)
			{
				iGreg = 0;
			}
			else
			{
				iGreg = 1;
			}
			if ((iMonth == 1) || (iMonth == 2))
			{
				iYear = iYear - 1;
				iMonth = iMonth + 12;
			}

			fA = (long)Math.Floor(iYear / 100);
			fB = (2 - fA + (long)Math.Floor(fA / 4)) * iGreg;
			if (iYear < 0)
			{
				fC = (int)Math.Floor((365.25 * iYear) - 0.75);
			}
			else
			{
				fC = (int)Math.Floor(365.25 * iYear);
			}
			fD = (int)Math.Floor(30.6001 * (iMonth + 1));
			fJD = fB + fC + fD + 1720994.5;
			fJD = fJD + fFrac;
			return fJD;
		}

Finding the date from the Julian day is found simply by inverting the calculations done above

		public static DateTime getDateFromJD(double fJD, int iZone)
		{
			DateTime dDate;
			int iYear;
			int fMonth;
			int iDay;
			int iHour;
			int iMinute;
			int iSecond;
			double fFrac;
			double fFracDay;
			int fI;
			int fA;
			int fB;
			int fC;
			int fD;
			int fE;
			int fG;

			fJD = fJD + 0.5;
			fI = (int)Math.Floor(fJD);
			fFrac = fJD - fI;

			if (fI > 2299160)
			{
				fA = (int)Math.Floor((fI - 1867216.25) / 36524.25);
				fB = fI + 1 + fA - (int)Math.Floor((double)(fA / 4));
			}
			else
			{
				fA = 0;
				fB = fI;
			}
			fC = fB + 1524;
			fD = (int)Math.Floor((fC - 122.1) / 365.25);
			fE = (int)Math.Floor(365.25 * fD);
			fG = (int)Math.Floor((fC - fE) / 30.6001);
			fFracDay = fC - fE + fFrac - (long)Math.Floor((double)(30.6001 * fG));
			iDay = (int)Math.Floor(fFracDay);
			fFracDay = (fFracDay - iDay) * 24;
			iHour = (int)Math.Floor(fFracDay);
			fFracDay = (fFracDay - iHour) * 60;
			iMinute = (int)Math.Floor(fFracDay);
			fFracDay = (fFracDay - iMinute) * 60;
			iSecond = (int)Math.Floor(fFracDay);

			if (fG < 13.5)
			{
				fMonth = fG - 1;
			}
			else
			{
				fMonth = fG - 13;
			}

			if (fMonth > 2.5)
			{
				iYear = (int)Math.Floor((double)(fD - 4716.0));
			}
			else
			{
				iYear = (int)Math.Floor((double)(fD - 4715.0));
			}


			dDate = new DateTime(iYear, (int)Math.Floor((double)fMonth), iDay, iHour, iMinute, iSecond);
			dDate = CalcZTFromUT(dDate, iZone);
			return dDate;
		}

Share