[英]How to convert Gregorian date to Coptic date in C#
How to convert Gregorian calendar to Coptic calendar in C# ?? 如何在C#中将公历转换为科普特历?
I have the following code: 我有以下代码:
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; }
}
I need to implement the following method 我需要实现以下方法
public static CopticDate ToCopticDate(this DateTime date)
{
//...
}
Like Marc, I have NodaTime in my toolbox for jobs like this. 像Marc一样,我的工具箱中也有NodaTime来完成这样的工作。 You'll need to install the Nuget package .
您需要安装Nuget软件包 。
The implementation is simple - we create a LocalDate
object from the input date, and convert it to the Coptic calendar using .WithCalendar(CalendarSystem.Coptic)
. 实现很简单-我们从输入日期创建
LocalDate
对象,然后使用.WithCalendar(CalendarSystem.Coptic)
将其转换为Coptic日历。 We then return an instance of your 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
};
}
With an input date of 6 September 2019, I get the following output: 输入日期为2019年9月6日,我将获得以下输出:
Day: 1
一天:1
Month: PiKogiEnavot
月:PiKogiEnavot
Year: 1735
年:1735
which so far as I can tell is the expected output. 据我所知,这是预期的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.