Converting Dates between Calendars in Xamarin.Android

一笑奈何 提交于 2021-01-29 03:57:14

问题


I have the following snippet of Code for Convert Gregorian Date to Hijri Date.

public static string GregoriantoHijri(DateTime gregorianDate)
{
    CultureInfo arCI = new CultureInfo("ar-SA");
    var hijriCalendar = new HijriCalendar();
    hijriCalendar.HijriAdjustment = App_Code.StoreRetrieveSettingsAssist.getHA();
    arCI.DateTimeFormat.Calendar = hijriCalendar;  //CODE FAILS HERE
    string hijriDate = gregorianDate.ToString("dd-MM-yyyy", arCI);

    return hijriDate;
}

This code runs perfectly for my Windows Mobile App which is also posted on Store. However the same code is giving me issues in Xamarin.Android

The Error:

System.ArgumentOutOfRangeException:
Not a valid calendar for the given culture.
Parameter name: value

I don't understand why codes using same .NET base class have issues on different platforms. Can you suggest a workaround cause this doesn't seem to work.


回答1:


You might want to consider NodaTime. It is supposedly more robust than the native .NET datetime handling, and is supposed to support Hijri.



来源:https://stackoverflow.com/questions/37092957/converting-dates-between-calendars-in-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!