ToLongDateString() 用阿拉伯语显示错误的日期

问题描述

在我的 ASP NET MVC 实体框架项目中,我从数据库中传递日期和时间信息。当我以阿拉伯语格式 CultureInfo("ar-AR") 显示日期时,我从数据库中输入的内容中得到一个错误的日期

到目前为止我的代码

datetime_created.ToLongDateString();
// The date I pass is:- 2020-12-10
// CultureInfo("en-US") in en-US culture it displays the date as it is in a database:- Thursday,December 10,2020
// CultureInfo("ar-AR") in ar-AE culture it displays another date:- 1442/ربيع الثاني/25

知道为什么会发生这种情况吗?

解决方法

当您使用 $> react-native doctor Common ✓ Node.js ✓ npm Android ✓ JDK ✖ Android Studio - Required for building and installing your app on Android ✓ Android SDK - Required for building and installing your app on Android ✓ ANDROID_HOME Errors: 1 Warnings: 0 Usage › Press f to try to fix issues. › Press e to try to fix errors. › Press w to try to fix warnings. › Press Enter to exit. 文化 - 阿拉伯语,阿拉伯联合酋长国时,您根据这种文化表示给定的 ar-AE 作为字符串。这是回历。

但是,您可以轻松创建自己的自定义文化,除了日期表示外,它将是 DateTime

ar-AE

结果:

  // The custom (myArabic) culture will be "ar-AE" one except date formatting 
  CultureInfo myArabic = CultureInfo.GetCultureInfo("ar-AE").Clone() as CultureInfo;

  // Let's use InvariantCulture DateTime rules 
  //TODO: specify all date time format settings here 
  myArabic.DateTimeFormat = CultureInfo.InvariantCulture.DateTimeFormat;

  DateTime test = new DateTime(2020,12,10);

  Console.Write(test.ToString("G",myArabic));