470,620 Members | 1,376 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,620 developers. It's quick & easy.

Converting From Julian to Gregorian DateTime

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

Oct 20 '05 #1
3 9210
Sunny,

I never did your problem, however i expect that using the Calender class
would give you the solution.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

Oct 21 '05 #2
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

Oct 21 '05 #3
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
Oct 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by ola Alli | last post: by
5 posts views Thread by Cameron | last post: by
14 posts views Thread by msavazzi | last post: by
5 posts views Thread by =?Utf-8?B?emlubw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.