【问题标题】:Convert juilan date (not as double, but date) to gregorian date将儒略日期(不是双精度,而是日期)转换为公历日期
【发布时间】:2016-02-19 09:54:56
【问题描述】:

我有一个儒略日期:1104-08-16,如何在 c# 中将其转换为公历?

我找到了以下链接...link link。但它们都使用儒略日期值作为浮点数/十进制数。

在我的情况下,朱利安不是浮动的,而是实际日期。

任何帮助将不胜感激。

【问题讨论】:

  • 您发布的链接与天文学中使用的“儒略日数字”有关。正如您所指出的,它们通常表示为浮点天数和小数天数。但看起来你实际拥有的是“儒略历”中的一个日期,这将是一个完全不同的转换。
  • 知道我该怎么做吗?
  • 两个问题。首先,你的 1104-08-16 是否已经在 c# 程序中,如果有,它属于什么类,字符串?其次,您是否想使用 DateTime 或 DateTimeOffset 类取决于您是否知道(并关心)日期发生的时区,那么您知道/关心吗?
  • 1104-08-16 是字符串(我们从管道分隔的文本文件中读取它)。我想我不必寻找时区,所以我会使用 datetime。

标签: c# gregorian-calendar julian-date


【解决方案1】:

如果您不知道或不关心时区,可以尝试以下方法。我使用这种方法是因为我找不到允许您指定解释输入的日历的解析方法。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;

namespace julian2gregorian
{
    class Program
    {
        private static JulianCalendar jcal;
        static void Main(string[] args)
        {
            jcal = new JulianCalendar();
            string jDateString = "1104-08-16";
            char[] delimiterChars = { '-' };
            string[] dateParts = jDateString.Split(delimiterChars);
            int jyear, jmonth, jday;
            bool success = int.TryParse(dateParts[0], out jyear);
            success = int.TryParse(dateParts[1], out jmonth);
            success = int.TryParse(dateParts[2], out jday);
            DateTime myDate = new DateTime(jyear, jmonth, jday, 0, 0, 0, 0, jcal);
            Console.WriteLine("Date converted to Gregorian: {0}", myDate);
            Console.ReadLine();
        }
    }
}

【讨论】:

    猜你喜欢
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 2011-03-02
    相关资源
    最近更新 更多