473,770 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9731
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 JulianToDateTim e(double julianDate)
{
DateTime date;
double Z, W, X, A, B, C, D, E, F;
int day, month, year;

try
{
Z = Math.Floor(juli anDate + 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.6 001 * 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 (ArgumentOutOfR angeException ex)
{
System.Windows. Forms.MessageBo x.Show("Julian date could not be
converted:\n" + ex.Message, "Conversion Error",
System.Windows. Forms.MessageBo xButtons.OK,
System.Windows. Forms.MessageBo xIcon.Error);

date = new DateTime(0);
}
catch (Exception ex)
{
System.Windows. Forms.MessageBo x.Show("Error converting Julian date:\n" +
ex.Message, "Conversion Error", System.Windows. Forms.MessageBo xButtons.OK,
System.Windows. Forms.MessageBo xIcon.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
45644
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
8711
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")); When I run it on my development PC it's fine - I get 1st October 2003. When I run it from my webserver it doesn't work - I get 10th January 2003.
3
503
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 is 100033 and I know that it is 2/2/2000 in Gregorian. I would appreciate if anyone can help point me out.
14
9466
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. Now why happens this:
4
1536
by: Ambrose | last post by:
"31-03-2007 10:00:00 AM" to Datetime .Regional Local settings is dutch (NL).Please help me .
0
1159
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 Logic Circuits) programs often store Date/Time in this format. The best I can work out is like this... Declare @Day Int Declare @Month Int
3
2563
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' test_templates.cpp:51: error: expected `)' before ';' token test_templates.cpp:51: error: invalid const_cast from type 'bar<lab2::Gregorian>' to type 'bar<lab2::Julian>*' where the Julian and Gregorian are date classes that inherit from Date How do I "make" the...
5
2067
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 DateTime Dim myCultureInfo As New CultureInfo("en-US") If DateTime.TryParseExact("Dec 18 2007 2:49:40:783PM", "mon dd yyyy hh:mi:ss:mmmAM", myCultureInfo, Globalization.DateTimeStyles.None, dt) Then .... ...
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.