Converting From Julian to Gregorian DateTime

S

sunny076

Hi,

I am trying to convert from Julian to Gregorian data in C#. I was
exploring teh JulianCalendar and Gregorian calendar classes but still
not sure how I can do it. For example, the Julian date is 100033 and I
know that it is 2/2/2000 in Gregorian.


I would appreciate if anyone can help point me out.

Thank you in advance,

Sunny
 
S

sunny076

Hi Cor,

Thanks for your help.

I had already looked at those classes but could not figure out how I
could convert the numeric Julian value to Gregorian DateTime value.
Would appreciate it if you have any insight.

Regards,
Sunny
 
G

Guest

There's a calculation for making this conversion at
http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html that seems to work for
julian dates like 2430705 (Dec 11, 1942). The JD you provide though (100033)
doesn't sync with the computation though, but I'm assuming there's some
factor missing you may be able to figure out.

Something like this:

private DateTime JulianToDateTime(double julianDate)
{
DateTime date;
double Z, W, X, A, B, C, D, E, F;
int day, month, year;

try
{
Z = Math.Floor(julianDate + 0.5);
W = Math.Floor((Z - 1867216.25) / 36524.25);
X = Math.Floor(W / 4);
A = Z + 1 + W - X;
B = A + 1524;
C = Math.Floor((B - 122.1) / 365.25);
D = Math.Floor(365.25 * C);
E = Math.Floor((B - D) / 30.6001);
F = Math.Floor(30.6001 * E);

day = Convert.ToInt32(B - D - F);
if (E > 13)
{
month = Convert.ToInt32(E - 13);
}
else
{
month = Convert.ToInt32(E - 1);
}

if ((month == 1) || (month == 2))
{
year = Convert.ToInt32(C - 4715);
}
else
{
year = Convert.ToInt32(C - 4716);
}

date = new DateTime(year, month, day);

return date;
}
catch (ArgumentOutOfRangeException ex)
{
System.Windows.Forms.MessageBox.Show("Julian date could not be
converted:\n" + ex.Message, "Conversion Error",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);

date = new DateTime(0);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Error converting Julian date:\n" +
ex.Message, "Conversion Error", System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);

date = new DateTime(0);
}

return date;
}

-- Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top