更改 CultureAndRegionInfoBuilder 的默认日历
我想将“th-TH”文化的默认日历从 ThaiBuddhist 更改为公历,并将其注册为自定义文化。
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("th-TH", CultureAndRegionModifiers.Replacement);
cultureAndRegionInfoBuilder.AvailableCalendars = new Calendar[] { new GregorianCalendar()};
cultureAndRegionInfoBuilder.Register();
以上部分不会更改默认日历。
CultureInfo cultureInfo = new CultureInfo("th-TH");
cultureInfo.DateTimeFormat.Calendar = new GregorianCalendar();
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("th-TH", CultureAndRegionModifiers.Replacement);
cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo);
cultureAndRegionInfoBuilder.Register();
这也行不通。
I want to change the default calender of 'th-TH' culture from ThaiBuddhist to Gregorian and register it as a custom culture.
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("th-TH", CultureAndRegionModifiers.Replacement);
cultureAndRegionInfoBuilder.AvailableCalendars = new Calendar[] { new GregorianCalendar()};
cultureAndRegionInfoBuilder.Register();
Above segment does not change the default calendar.
CultureInfo cultureInfo = new CultureInfo("th-TH");
cultureInfo.DateTimeFormat.Calendar = new GregorianCalendar();
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("th-TH", CultureAndRegionModifiers.Replacement);
cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo);
cultureAndRegionInfoBuilder.Register();
This does not work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你不能那样做。实际上,有更简单的方法来覆盖默认日历:
这适用于我的控制台应用程序。唯一的问题是,它可能不适合你。为什么?我认为您提到的“SSRS 服务器端报告”作为不同的进程运行,我可能是错的,但我很确定您只能覆盖当前进程的 CultureInfo 设置。我认为这不能(也不应该)在全球范围内完成。
另外,我不知道您正在使用的报告解决方案的具体情况,因此它可能没有帮助,但是您不能将已经格式化的日期时间字符串作为参数传递吗?这就是水晶报表中解决这个问题的方法。最坏的情况是将格式化字符串写入数据库。
I don't think you can do it that way. Actually, there would be the easier way to override default calendar:
That works for my console application. The only problem, it probably won't work for you. Why? I think that "SSRS Server Side Reporting" you mentioned run as a different process and I might be wrong, but I am pretty sure that you can override CultureInfo setting only for your current process. I don't think it could (and should) be done globally.
Also, I don't know specifics of reporting solution you are using, so it might be of no help, but couldn't you just pass already formatted date-time strings as parameters? That would be the way to solve it in i.e. Crystal Reports. The worst case scenario would be to write down formatted strings to database.
由于您正在修改现有区域性(替换),因此您无法删除日历,但可以对它们重新排序:
由于它是替换区域性,因此在开始新流程之前您不会看到效果。
Since you are modifying an existing culture (replacement) you cannot remove calendars, but you can reorder them:
Since it is a replacement culture, you won't see the effect until you start a new process.
如果不先删除现有文化,则无法更改它:
You can't change an existing Culture without removing it first: