Microsoft Developer Network > 포럼 홈 > .NET Base Class Library > PersianCalendar as CurrentCulture
질문하기질문하기
 

답변됨PersianCalendar as CurrentCulture

  • 2005년 12월 2일 금요일 오후 10:35Mohammad Mir mostafa 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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?

답변

  • 2006년 9월 5일 화요일 오후 5:53Emad Rangchi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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.

모든 응답

  • 2006년 3월 5일 일요일 오전 11:26Mohammad Mir mostafa 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    No body knows how to do that?
  • 2006년 9월 5일 화요일 오후 5:53Emad Rangchi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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.

  • 2006년 9월 16일 토요일 오전 5:26Mohammad Mir mostafa 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Thanks dear Emad.
  • 2007년 8월 9일 목요일 오전 5:53Masoud_TB 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     제안된 답변
    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
    •  
  • 2009년 9월 29일 화요일 오전 7:00M. Abbasi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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
  • 2009년 10월 13일 화요일 오전 10:36Mohammad Mir mostafa 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Check this out.
    Mohammad - C# Lover
  • 2009년 11월 8일 일요일 오전 7:46M. Abbasi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    thank you my friend for your reply.

    wish to have good days for you