简体   繁体   中英

Converting Dates between Calendars in Xamarin.Android

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM