微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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));

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。