Sidereal time is the time in relation to the stars. Normal time is calculated as the time it takes for the earth to spin once about its axis to the same point in relation to the Sun, so for example from when the Sun is directly overhead to the next time the Sun is directly overhead. The total time for this to happen is 24 hours.

If we instead use the stars as our reference point, the length of a day is slightly shorter, by 4 minutes, thus making a sidereal day 23 hours 54 minutes.

The reason for this is that during the day, the Earth has moved 1/365th of the way further in its orbit around the sun, so once the Earth has made one full rotation, it has to rotate just that little bit more to have the Sun in the same position.

What this means though as well is that a year is made up of 366 sidereal days as opposed to 365 days in the normal year (rounded off here).

We also talk about Greenwich Sidereal Time (GST) and Local Sideral Time (LST) which are analogous to Universal Time and Local Mean Time.

Finding the GST, we work with the Julian day, which was covered in a previous tutorial. Working from an epoch (a date where we know where everything is) Julian Day of 2451545.0, where we know the Sidereal time was the same as the UT. First we need work out the time difference from the current date to that date, and once we have this we can calculate the amount of precession to take into account, which I will talk more about in a future tutorial, which is stored in fT0. We then convert the UT to a decimal format, so that we can multiply by the multiplication factor to put the UT into GST, and then add in the precessional amount.

We then need to put the final answer into the 24 hour range before returning the result.

		public static DateTime CalcGSTFromUT(DateTime dDate)
		{
			double fJD;
			double fS;
			double fT;
			double fT0;
			DateTime dGST;
			double fUT;
			double fGST;

			fJD = GetJulianDay(dDate.Date, 0);
			fS = fJD - 2451545.0;
			fT = fS / 36525.0;
			fT0 = 6.697374558 + (2400.051336 * fT) + (0.000025862 * fT * fT);
			fT0 = Trig.PutIn24Hour(fT0);
			fUT = ConvTimeToDec(dDate);
			fUT = fUT * 1.002737909;
			fGST = fUT + fT0;
			while (fGST > 24)
			{
				fGST = fGST - 24;
			}
			dGST = ConvDecTUraniaTime(fGST);
			return dGST;
		}

		public static DateTime ConvDecTUraniaTime(double fTime)
		{
			DateTime dDate;

			dDate = new DateTime();
			dDate = dDate.AddHours(fTime);
			return (dDate);
		}

		public static double ConvTimeToDec(DateTime dDate)
		{
			double fHour;

			fHour = dDate.Hour + (dDate.Minute / 60.0) + (dDate.Second / 60.0 / 60.0) + (dDate.Millisecond / 60.0 / 60.0 / 1000.0);
			return fHour;
		}

Now converting the other way round, we just do the reverse. We work out fT0 as before, and then subtract it from the GST. We then put it into 24 hours, before multiplying by the inverse of the scaling factor we used in when going in the other direction.

We then have the UT.

		public static DateTime CalcUTFromGST(DateTime dGSTDate, DateTime dCalDate)
		{
			double fJD;
			double fS;
			double fT;
			double fT0;
			double fGST;
			double fUT;
			DateTime dUT;

			bool bPrevDay;
			bool bNextDay;

			bPrevDay = false;
			bNextDay = false;

			fJD = GetJulianDay(dCalDate.Date, 0);
			fS = fJD - 2451545.0;
			fT = fS / 36525.0;
			fT0 = 6.697374558 + (2400.051336 * fT) + (0.000025862 * fT * fT);

			fT0 = Trig.PutIn24Hour(fT0);

			fGST = ConvTimeToDec(dGSTDate);
			fGST = fGST - fT0;
		
			while (fGST > 24)
			{
				fGST = fGST - 24;
				bNextDay = true;
			}
			while (fGST < 0)
			{
				fGST = fGST + 24;
				bPrevDay = true;
			}

			fUT = fGST * 0.9972695663;
			// fUT = fGST
		
			dUT = dCalDate.Date;
			dUT = dUT.AddHours(fUT);
			fUT = dUT.Millisecond;
			
			if (bNextDay == true)
			{
				dUT = dUT.AddDays(1);
			}

			if (bPrevDay == true)
			{
				dUT = dUT.Subtract(new TimeSpan(1, 0, 0, 0, 0));
			}
			return dUT;
		}
Share