Hijri and Gregorian DateTime constructor

前端 未结 2 2056
半阙折子戏
半阙折子戏 2020-12-19 21:58

what is the correct behavior for the Calendar objected passed to the constructor of DateTime type?

I have the components year, month and day as the below example:

相关标签:
2条回答
  • 2020-12-19 22:07

    Your first example is correct. The DateTime will not be in the Hijri format, it will just be the standardised equivalent of what you gave it. See the following code for how to get the Hirji date:

    HijriCalendar hijri = new HijriCalendar();
    DateTime firstDayInMonth = new DateTime(1433, 10, 11, hijri);
    Console.WriteLine(hijri.GetEra(firstDayInMonth)); // 1
    Console.WriteLine(hijri.GetYear(firstDayInMonth)); // 1433
    Console.WriteLine(hijri.GetMonth(firstDayInMonth)); // 10
    Console.WriteLine(hijri.GetDayOfMonth(firstDayInMonth)); // 11
    

    Your second block of code was just setting the gregorian date "1/1/1433" so when you were inspecting it you weren't getting a hirji date, you were just getting the date you gave it in the 15th century.

    Looking at http://msdn.microsoft.com/en-us/library/system.globalization.hijricalendar.aspx and seeing the methods there should give you a better idea of what you should be doing on the calendar object and what should happen on the DateTime object.

    0 讨论(0)
  • 2020-12-19 22:22

    You've not actually asked a meaningful question. If you're trying to convert a given date from one calender to another then more than the date will change, after all the Hijri calender has different months to the gregorian.

    Check out this site for examples - it even has downloadable code.

    0 讨论(0)
提交回复
热议问题