iLLkeeN Nemo
iLLkeeN Nemo

Reputation: 41

How to convert Julian Date to UTC in c#

I convert from UTC to Julian Date. But I need to convert Julian Date to UTC. I researched but I didn't find any code in c#

I did UTC to Julian Date I need Julian Date to UTC

Upvotes: 2

Views: 608

Answers (2)

MarkovskI
MarkovskI

Reputation: 1587

You can use the NodaTime library FromJulianDayNumber method to do the conversion to an instant from which you can get UTC, it will handle all of the minutia that the accepted answer does not handle.

Upvotes: 0

Stevo
Stevo

Reputation: 1444

Create this extension method:

public static class DoubleExtensions
{
    public static DateTime JulianDateToUtc(this double julianDate)
    {
        var sinceEpoch = julianDate - 2440587.500000D;

        return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddDays(sinceEpoch);
    }
}

Then you can just do:

2458324.500000D.JulianDateToUtc();

Upvotes: 2

Related Questions