PersianCalendar as CurrentCulture
- Hi,
My main language is persian, and use persian calendar as my main calendar, but when i wanna use:
... .CurrentCulture.DateTimeFormat.Calendar =
new System.Globalization.PersianCalendar();
it gives me an error.
can anybody help me, or give me a short source code, too correct it?
답변
Dear Mohammad
I should notice you about whatever wrote in MSDN
Use a PersianCalendar object to calculate dates in the Persian calendar, or to convert Persian dates to and from Gregorian dates.
Do 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.

모든 응답
- No body knows how to do that?
Dear Mohammad
I should notice you about whatever wrote in MSDN
Use a PersianCalendar object to calculate dates in the Persian calendar, or to convert Persian dates to and from Gregorian dates.
Do 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.

- Thanks dear Emad.
- Dear Mr.Emad,
here is the code that you can use to set PersianCalendar as default calendar for thread:
System.Globalization.CultureInfo calture = new System.Globalization.CultureInfo("fa-IR");
System.Globalization.DateTimeFormatInfo info = calture.DateTimeFormat;
info.AbbreviatedDayNames = new string[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
info.DayNames = new string[] { "یکشنبه", "دوشنبه", "ﺳﻪشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" };
info.AbbreviatedMonthNames = new string[] { "فروردین", "ارديبهشت", "خرداد", "تير", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.MonthNames = new string[] { "فروردین", "ارديبهشت", "خرداد", "تير", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.AMDesignator = "ق.ظ";
info.PMDesignator = "ب.ظ";
info.ShortDatePattern = "yyyy/MM/dd";
info.FirstDayOfWeek = DayOfWeek.Saturday;
System.Globalization.PersianCalendar cal = new System.Globalization.PersianCalendar();
typeof(System.Globalization.DateTimeFormatInfo).GetField("calendar", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(info, cal);
object obj = typeof(System.Globalization.DateTimeFormatInfo).GetField("m_cultureTableRecord", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(info);
obj.GetType().GetMethod("UseCurrentCalendar", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(obj, new object[] { cal.GetType().GetProperty("ID", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(cal, null) });
typeof(System.Globalization.CultureInfo).GetField("calendar", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(calture, cal);
typeof(System.Globalization.CultureInfo).GetField("calendar", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(calture, cal);
System.Threading.Thread.CurrentThread.CurrentCulture = calture;
System.Threading.Thread.CurrentThread.CurrentUICulture = calture;
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat = info;
System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat = info;
then you can use DateTime class in Persian and also Calendar of ASP .NET will show you the Shami dates.- 답변으로 제안됨moradidn 2008년 5월 30일 금요일 오후 2:50
- thank you very much
but what about windows forms? i tested the code in there but not succeeded
can you suggest such resolution for using in windows forms?
maysam.abbasi@gmail.com - Check this out.
Mohammad - C# Lover - thank you my friend for your reply.
wish to have good days for you

