Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julian date string to DateTime

I am trying to convert Julian date string to DateTime but none of the solutions on the web seem to be working. I have a Julian date string 13324.

Julian Date: 13324

And I want to get the following DateTime

Date: 20-Nov-2013

Could you please direct me in the right direction. Thanks.

like image 262
Oxon Avatar asked Dec 02 '25 05:12

Oxon


2 Answers

This is the simplest solution I can think of:

string julianDate = "13324";

int jDate = Convert.ToInt32(julianDate);
int day = jDate % 1000;
int year = (jDate - day) / 1000;
var date1 = new DateTime(year, 1, 1);
var result = date1.AddDays(day - 1);

(Note: this is all from memory; verify the syntax, etc.)

like image 50
Ann L. Avatar answered Dec 03 '25 19:12

Ann L.


Sorry for my bad english

Try this code if the one on top didn't work. It worked for me.

public DateTime ConvertJulianToDatetime(string julianDate)
{
    int dateint = int.Parse(julianDate);

    DateTime dinicio = new DateTime(1840, 12, 31);
    dinicio = dinicio.AddDays((double)dateint);
    return dinicio;
}
like image 24
Hugo Araújo Avatar answered Dec 03 '25 19:12

Hugo Araújo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!