Persian Calendar not valid with CultureInfo

爱⌒轻易说出口 提交于 2019-12-08 16:31:19

问题


What's wrong with this code?

Error(Exception) message :

Not a valid calendar for the given culture.

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("fa-Ir"); //Error
ci.DateTimeFormat.Calendar = new System.Globalization.PersianCalendar();
Application.CurrentCulture = ci;

And what's its solution?
Can I add a Calendar type to Windows XP regional option?


回答1:


a dirty reflection-based workaround is here :

http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/4768d48e-aa04-4c15-b688-a58fa4373bc9/




回答2:


It is explicitly mentioned in the MSDN article for PersianCalendar

Your application should not use a PersianCalendar object as the default calendar for a culture. The default calendar is specified by the CultureInfo.Calendar property and must be one of the calendars returned by the CultureInfo.OptionalCalendars property. Currently, the PersianCalendar class is not an optional calendar for any culture supported by the CultureInfo class and consequently cannot be a default calendar.

You cannot make this work. Use the Calendar as-is.



来源:https://stackoverflow.com/questions/5449085/persian-calendar-not-valid-with-cultureinfo

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