本文整理匯總了C#中System.Globalization.PersianCalendar.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# PersianCalendar.GetType方法的具體用法?C# PersianCalendar.GetType怎麽用?C# PersianCalendar.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Globalization.PersianCalendar
的用法示例。
在下文中一共展示了PersianCalendar.GetType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetPersianCulture
public static CultureInfo GetPersianCulture()
{
//*****************************************************************************
//*****************************2008-04-02 By A. Samarian*****Begin*************
//Modified:2010-09-18
//Modified by: Asad Samarian
//*****************************************************************************
CultureInfo persianCulture = new CultureInfo("fa-IR");
DateTimeFormatInfo info = persianCulture.DateTimeFormat;
info.DayNames = new string[] { "یکشنبه", "دوشنبه", "ﺳﻪشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" };
info.AbbreviatedDayNames = new string[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
info.MonthNames = new string[] { "فروردین", "ارديبهشت", "خرداد", "تير", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.AbbreviatedMonthNames = new string[] { "فروردین", "ارديبهشت", "خرداد", "تير", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
//It Seems .NET 4 use Genitive manes for months.
info.MonthGenitiveNames = new string[] { "فروردین", "ارديبهشت", "خرداد", "تير", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.AbbreviatedMonthGenitiveNames = new string[] { "فروردین", "ارديبهشت", "خرداد", "تير", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.AMDesignator = "ق.ظ";
info.PMDesignator = "ب.ظ";
info.ShortDatePattern = "yyyy/MM/dd";
info.LongDatePattern = "dddd dd MMMM yyyy";
info.FullDateTimePattern = "dddd dd MMMM yyyy, HH:mm:ss";
info.FirstDayOfWeek = DayOfWeek.Saturday;
PersianCalendar cal = new PersianCalendar();
// 2010-07-18 this part throws an error under .NET 4, Asad says it is still needed for 3.5
if (ConfigHelper.GetBoolProperty("UseNet35PersianHelper", false)) //this setting is true in the We.config for 3.5 .NET but not 4.0
{
typeof(DateTimeFormatInfo).GetField("calendar", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).SetValue(info, cal);
object obj = typeof(DateTimeFormatInfo).GetField("m_cultureTableRecord",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).GetValue(info);
obj.GetType().GetMethod("UseCurrentCalendar",
BindingFlags.NonPublic | BindingFlags.Instance).Invoke(obj, new object[] { cal.GetType().GetProperty("ID", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(cal, null) });
//typeof(DateTimeFormatInfo).GetField("calendar", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).SetValue(info, cal);
//typeof(CultureInfo).GetField("calendar", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).SetValue(persianCulture, cal);
}
typeof(DateTimeFormatInfo).GetField("calendar", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).SetValue(info, cal);
typeof(CultureInfo).GetField("calendar", (BindingFlags.NonPublic | (BindingFlags.Public | BindingFlags.Instance))).SetValue(persianCulture, cal);
persianCulture.DateTimeFormat = info;
persianCulture.NumberFormat.CurrencyDecimalDigits = 0;
return persianCulture;
//*****************************************************************************
//*************************2008-04-02 By A. Samarian*****End*******************
//Modified:2010-09-18
//Modified by: Asad Samarian
//*****************************************************************************
}
示例2: SetPersianCalendar
public static void SetPersianCalendar()
{
CultureInfo info = new CultureInfo("fa-IR")
{
NumberFormat = { DigitSubstitution = DigitShapes.NativeNational }
};
DateTimeFormatInfo dateTimeFormat = info.DateTimeFormat;
dateTimeFormat.AMDesignator = "ق.ظ";
dateTimeFormat.PMDesignator = "ب.ظ";
dateTimeFormat.DateSeparator = "/";
dateTimeFormat.ShortDatePattern = "yyyy/MM/dd";
dateTimeFormat.FirstDayOfWeek = DayOfWeek.Saturday;
dateTimeFormat.AbbreviatedDayNames = new[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
dateTimeFormat.DayNames = new[] { "یکشنبه", "دوشنبه", "سهشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" };
dateTimeFormat.MonthGenitiveNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
dateTimeFormat.ShortestDayNames = new[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
dateTimeFormat.AbbreviatedMonthNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
dateTimeFormat.MonthNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
PersianCalendar calendar = new PersianCalendar();
typeof(DateTimeFormatInfo).GetField("calendar", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).SetValue(dateTimeFormat, calendar);
object obj2 = typeof(DateTimeFormatInfo).GetField("m_cultureTableRecord", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).GetValue(dateTimeFormat);
obj2.GetType().GetMethod("UseCurrentCalendar", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(obj2, new[] { calendar.GetType().GetProperty("ID", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(calendar, null) });
typeof(CultureInfo).GetField("calendar", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).SetValue(info, calendar);
Thread.CurrentThread.CurrentCulture = info;
Thread.CurrentThread.CurrentUICulture = info;
CultureInfo.CurrentCulture.DateTimeFormat = dateTimeFormat;
CultureInfo.CurrentUICulture.DateTimeFormat = dateTimeFormat;
}