gpt4 book ai didi

c# - CultureInfo 和 DateTimeFormatInfo 的全局化 : How can we change digits format to my language?

转载 作者:太空宇宙 更新时间:2023-11-03 18:44:33 24 4
gpt4 key购买 nike

我使用 System.Globalization 如下:

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;

我的问题是:

  1. 为什么注释行在 VS2010(.NET 4.0)中有错误,但在 VS2008(.NET 3.5)中没有问题?

  2. 当我使用 DateTime.Now 时如何本地化我的数字,我的意思是我想要我的语言格式的数字(Just For DateTime)!可能吗?

在此先致谢并致以最诚挚的问候。

最佳答案

请看this回答。还有 that one可能会有帮助。基本思想是创建一个扩展方法,将数字替换为东阿拉伯数字。顺便提一句。似乎已经为 ps-AF 区域性定义了数字和一些月份/日期名称:

        // gets Eastern Arabic digits array
string[] numerals = CultureInfo.CreateSpecificCulture("ps-AF").NumberFormat.NativeDigits;

就是不知道适不适合你。

关于c# - CultureInfo 和 DateTimeFormatInfo 的全局化 : How can we change digits format to my language?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5611413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com