简体   繁体   English

在 Xamarin.Android 中的日历之间转换日期

[英]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.此代码非常适合我的 Windows Mobile 应用程序,该应用程序也发布在 Store 上。 However the same code is giving me issues in Xamarin.Android但是,相同的代码在 Xamarin.Android 中给我带来了问题

The Error:错误:

System.ArgumentOutOfRangeException: 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.我不明白为什么使用相同 .NET 基类的代码在不同平台上有问题。 Can you suggest a workaround cause this doesn't seem to work.您能否提出解决方法,因为这似乎不起作用。

You might want to consider NodaTime .您可能需要考虑NodaTime It is supposedly more robust than the native .NET datetime handling, and is supposed to support Hijri .据说它比本机 .NET 日期时间处理更健壮,并且应该支持Hijri

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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