简体   繁体   English

将juilan日期(不是双精度,而是日期)转换为公历

[英]Convert juilan date (not as double, but date) to gregorian date

I have a julian date : 1104-08-16, How do I convert it into gregorian date in c#? 我有一个儒略日期:1104-08-16,如何在C#中将其转换为公历?

I found following links... link link . 我发现以下链接... 链接 链接 But all of them use julian date value as float/decimal. 但是它们都使用julian日期值作为float / decimal。

In my case julian is not float, it is actual date. 就我而言,朱利安不是浮动的,它是实际日期。

Any help would be appreciated. 任何帮助,将不胜感激。

If you don't know or care about time zones, you could try the following. 如果您不了解或不关心时区,可以尝试以下方法。 I used this approach because I couldn't find a parse method that allowed you to specify which calendar to interpret the input. 之所以使用这种方法,是因为我找不到允许您指定哪个日历来解释输入的解析方法。

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();
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM