与时间(H / M / S)转换朱利安日期以日期时间在C# [英] Convert Julian Date with Time (H/m/s) to Date Time in C#

查看:526
本文介绍了与时间(H / M / S)转换朱利安日期以日期时间在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换Julian日期与时间 - 例如2456961.090914(CE 2014年14年10月30日:10:54.6 UT),你可以在这个网站上测试:的 http://aa.usno.navy.mil/data/docs/JulianDate.php 在C#中?_爱
我尝试了几种算法,我在网上找到,但有些不考虑朱利安作为双击,只甚至 INT 。其他一些使用 DateTime.ToOADate ,我没有在的System.DateTime 搜索结果
口如何给定的儒略历转换为常规/常规的DateTime?

How can I convert a Julian Date with Time - e.g. 2456961.090914 (CE 2014 October 30 14:10:54.6 UT) as you can test on this website: http://aa.usno.navy.mil/data/docs/JulianDate.php in C#?

I tried several algorithms I found on the net, but some don't contemplate the Julian as a double, only long or even int. Some other use DateTime.ToOADate that I do not have in the System.DateTime.

How can I convert the given Julian Date to a normal/regular DateTime?

推荐答案

由于Zator先生回答< A HREF =https://social.msdn.microsoft.com/Forums/windowsapps/en-US/12bde6a1-3888-4857-bf71-a9fcadbe9c62/convert-julian-date-with-time-hms-to-date-时间在-C论坛= csharpgeneral相对=nofollow>这里我能解决我的问题,像这样:

Thanks to Mr. Zator answer here I was able to solve my problem like so:

public DateTime JulianToDateTime(double julianDate) {
    double unixTime = (julianDate - 2440587.5) * 86400;

    DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds(unixTime).ToLocalTime();

    return dtDateTime;
}



值得一提的,虽然,这仅适用于行政长官朱利安日期类型,如果儒略历是BCE的类型将无法正常工作,需要为someother功能。我还做了这种方法看起来像这样的相反版本:

It is worth mentioning though, that this only works for CE Julian Date types, if the Julian Date is in BCE type it will not work, someother function is needed for that. I also made the opposite version of this method that looks like this:

public double DateTimeToJulian(DateTime dateTime) {
    DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
    TimeSpan diff = dateTime.ToUniversalTime() - origin;
    double unixTime = Math.Floor(diff.TotalSeconds);
    double julianDate = (unixTime / 86400) + 2440587.5;

    return julianDate;
}

这篇关于与时间(H / M / S)转换朱利安日期以日期时间在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆