473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 9632
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ola Alli | last post by:
Hi All, How do you convert int value to datetime datatype in sql server e.g 900mins to hh:mm:ss Regards Ola
5
by: Cameron | last post by:
I accept a date from a user in a textbox, but I need to convert it to a DateTime. I have the following code: return DateTime.ParseExact("01/10/2003", "dd/MM/yyyy", new CultureInfo("en-GB")); ...
3
by: sunny076 | last post by:
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...
14
by: msavazzi | last post by:
Hi, it should be simple, put FILETIME in a Long conver it in date using the DateTime.FromFileTimeUtc The help even says: Converts the specified Windows file time to an equivalent UTC time. ...
4
by: Ambrose | last post by:
"31-03-2007 10:00:00 AM" to Datetime .Regional Local settings is dutch (NL).Please help me .
0
by: DeePeeJay | last post by:
Hello, Is there a better way to convert separate integer values, representing Day, Month, Year, Hour, Minute and Second to DateTime? I work in the Automation Industry and PLC (Programmable...
3
by: nisse2562 | last post by:
this code: http://pastebin.com/f168570c8 gives the compile error: test_templates.cpp: In function 'int main(int, char**)': test_templates.cpp:51: error: expected `(' before 'g'...
5
by: =?Utf-8?B?emlubw==?= | last post by:
I need to convert a string as: "DEC 18 2007 2:49:40:783PM" to a date. This value is sent by SQL server as :select convert(varchar(30), creationDate, 109) from ... ... . I tried : Dim dt As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.