Photo Gallery

Wednesday, October 11, 2017

Julian date YYDDD to DateTime Conversion with C#

In this post, i will give you the Julian date to normal date time conversion code using c#.


Julian dates ( AKA JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BC (on the Julian calendar). Julian dates are widely used as time variables within astronomical software.

// Code to convert Julian Date to Normal Date Time
string julianDate = "80145";
int jDate = Convert.ToInt32(julianDate);
int day = jDate % 1000;
int year = (jDate - day) / 1000;
year = (year >= 17) ? year += 1900 : year += 2000;
var tempDate = new DateTime(year, 1, 1);
var result = tempDate.AddDays(day - 1);
// Optional
// string date = result.ToString("ddMMyyyy");
input : 80145
Output : 5/24/1980 12:00:00 AM
input : 13185
Output : 7/4/2013 12:00:00 AM
If you have any questions, post here. Also, provide your valuable suggestions and thoughts in form of comments in the section below.

Thank you

No comments:

Post a Comment