如何在 C# 中将公历日期转换为科普特日期
How to convert Gregorian date to Coptic date in C#
如何在 C# 中将公历转换为科普特历??
我有以下代码:
public enum CopticMonth
{
Thout = 1,
Paopi = 2,
Hathor = 3,
Koiak = 4,
Tobi = 5,
Meshir = 6,
Paremhat = 7,
Parmouti = 8,
Pashons = 9,
Paoni = 10,
Epip = 11,
Mesori = 12,
PiKogiEnavot = 13
}
public class CopticDate
{
public int Day { get; set; }
public CopticMonth Month { get; set; }
public int Year { get; set; }
}
我需要实现以下方法
public static CopticDate ToCopticDate(this DateTime date)
{
//...
}
像马克一样,我有 NodaTime in my toolbox for jobs like this. You'll need to install the Nuget package。
实施很简单 - 我们从输入日期创建一个 LocalDate
对象,并使用 .WithCalendar(CalendarSystem.Coptic)
将其转换为科普特日历。然后我们 return 你的一个实例 class:
public static CopticDate ToCopticDate(this DateTime date)
{
var localDate = LocalDate.FromDateTime(date, CalendarSystem.Gregorian)
.WithCalendar(CalendarSystem.Coptic);
return new CopticDate
{
Day = localDate.Day,
Month = (CopticMonth)localDate.Month,
Year = localDate.Year
};
}
输入日期为 2019 年 9 月 6 日,我得到以下输出:
Day:
1
Month:
PiKogiEnavot
Year:
1735
其中 so far as I can tell 是预期的输出。
如何在 C# 中将公历转换为科普特历??
我有以下代码:
public enum CopticMonth
{
Thout = 1,
Paopi = 2,
Hathor = 3,
Koiak = 4,
Tobi = 5,
Meshir = 6,
Paremhat = 7,
Parmouti = 8,
Pashons = 9,
Paoni = 10,
Epip = 11,
Mesori = 12,
PiKogiEnavot = 13
}
public class CopticDate
{
public int Day { get; set; }
public CopticMonth Month { get; set; }
public int Year { get; set; }
}
我需要实现以下方法
public static CopticDate ToCopticDate(this DateTime date)
{
//...
}
像马克一样,我有 NodaTime in my toolbox for jobs like this. You'll need to install the Nuget package。
实施很简单 - 我们从输入日期创建一个 LocalDate
对象,并使用 .WithCalendar(CalendarSystem.Coptic)
将其转换为科普特日历。然后我们 return 你的一个实例 class:
public static CopticDate ToCopticDate(this DateTime date)
{
var localDate = LocalDate.FromDateTime(date, CalendarSystem.Gregorian)
.WithCalendar(CalendarSystem.Coptic);
return new CopticDate
{
Day = localDate.Day,
Month = (CopticMonth)localDate.Month,
Year = localDate.Year
};
}
输入日期为 2019 年 9 月 6 日,我得到以下输出:
Day: 1
Month: PiKogiEnavot
Year: 1735
其中 so far as I can tell 是预期的输出。