I use System.Globalization
like below:
CultureInfo calture = new CultureInfo(MyCultureInfoGoesHere);
DateTimeFormatInfo info = calture.DateTimeFormat;
info.AbbreviatedDayNames = new string[] { "bla", "bla", "bla", "bla", "bla", "bla", "bla" };
info.ShortestDayNames = new string[] { "bla", "bla", "bla", "bla", "bla", "bla", "bla" };
info.DayNames = new string[] { "bla", "bla", "bla", "bla", "bla", "bla", "bla" };
info.AbbreviatedMonthNames = new string[] { "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "" };
info.MonthNames = new string[] { "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "bla", "" };
info.AMDesignator = "bla";
info.PMDesignator = "bla";
info.ShortDatePattern = "yyyy/MM/dd";
//info.ShortDatePattern = "dd/MM/yyyy";
info.LongDatePattern = "dddd , dd MMMM yyyy";
info.FirstDayOfWeek = DayOfWeek.bla;
MyCalendar cal = new MyCalendar();
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(System.Globalization.CultureInfo).GetField("calendar", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).SetValue(calture, cal);
Thread.CurrentThread.CurrentCulture = calture;
Thread.CurrentThread.CurrentUICulture = calture;
CultureInfo.CurrentCulture.DateTimeFormat = info;
CultureInfo.CurrentUICulture.DateTimeFormat = info;
My questions are:
Why do the commented lines have errors in VS2010 (.NET 4.0), but they're ok in VS2008 (.NET 3.5)?
How can I localize my digits when I use
DateTime.Now
, I mean I want digits format in my language(Just For DateTime)! is it possible?
Thanks in advance and best regards.