DateTime和朱利安日历-什么';DateTime.ToString()有什么问题吗?

DateTime和朱利安日历-什么';DateTime.ToString()有什么问题吗?,datetime,printing,calendar,tostring,julian-date,Datetime,Printing,Calendar,Tostring,Julian Date,我有一个应用程序,其中我将公历与日期时间一起使用。最近,如果用户需要,我决定让应用程序也使用朱利安日历(仍然有人使用这个日历)。起初事情似乎很简单。我可以在DateTime构造函数中指定使用的日历: var calend = new JulianCalendar(); DateTime dt = new DateTime(year, j, i, calend); 我可以得到每个月的天数和一周中的哪一天(这似乎与公历不同!): 现在,让我惊讶和困扰的是DateTime.ToString()的输出

我有一个应用程序,其中我将公历与日期时间一起使用。最近,如果用户需要,我决定让应用程序也使用朱利安日历(仍然有人使用这个日历)。起初事情似乎很简单。我可以在DateTime构造函数中指定使用的日历:

var calend = new JulianCalendar();
DateTime dt = new DateTime(year, j, i, calend);
我可以得到每个月的天数和一周中的哪一天(这似乎与公历不同!):

现在,让我惊讶和困扰的是
DateTime.ToString()
的输出。它似乎打印了公历中的日期:

目前,任何文化都不使用JulianCalendar 由CultureInfo类支持;因此,这个类只能是 用于计算儒略历中的日期

因为波斯日历不能指定为默认日历 区域性日历,在波斯日历中显示日期 需要单独调用其PersianCalendar.GetMonth, PersianCalendar.GetDayOfMonth和PersianCalendar.GetYear方法


那么,在儒略历中打印日期的最简单方法是什么?

使用扩展方法:

static class JulianPrinter
{
    public static string ToString(this DateTime date, string format, CultureInfo ci, Calendar cal)
    {
        if (format == "D")
            return string.Format("{0}, {1} {2} {3}",
                ci.DateTimeFormat.GetDayName(cal.GetDayOfWeek(date)),
                cal.GetDayOfMonth(date),
                ci.DateTimeFormat.MonthGenitiveNames[cal.GetMonth(date) - 1], //ci.DateTimeFormat.GetMonthName(cal.GetMonth(date)),
                cal.GetYear(date));
        return "";
    }
}
……和:

var calend = new JulianCalendar();
DateTime dt = new DateTime(year, j, i, calend);
string printed = dt.ToString("D", ci, calend);
var calend = new JulianCalendar();
DateTime dt = new DateTime(year, j, i, calend);
string printed = dt.ToString("D", ci, calend);