更改 CultureAndRegionInfoBuilder 的默认日历

发布于 2024-10-07 20:05:27 字数 775 浏览 8 评论 0原文

我想将“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情魔剑神 2024-10-14 20:05:27

我认为你不能那样做。实际上,有更简单的方法来覆盖默认日历:

        CultureInfo thaiCulture = CultureInfo.CreateSpecificCulture("th-TH");
        Console.Out.WriteLine(DateTime.Now.ToString(thaiCulture));
        DateTimeFormatInfo thaiDateTimeFormat = thaiCulture.DateTimeFormat;
        thaiDateTimeFormat.Calendar = new GregorianCalendar();
        Console.Out.WriteLine(DateTime.Now.ToString(thaiCulture));

这适用于我的控制台应用程序。唯一的问题是,它可能不适合你。为什么?我认为您提到的“SSRS 服务器端报告”作为不同的进程运行,我可能是错的,但我很确定您只能覆盖当前进程的 CultureInfo 设置。我认为这不能(也不应该)在全球范围内完成。

另外,我不知道您正在使用的报告解决方案的具体情况,因此它可能没有帮助,但是您不能将已经格式化的日期时间字符串作为参数传递吗?这就是水晶报表中解决这个问题的方法。最坏的情况是将格式化字符串写入数据库。

I don't think you can do it that way. Actually, there would be the easier way to override default calendar:

        CultureInfo thaiCulture = CultureInfo.CreateSpecificCulture("th-TH");
        Console.Out.WriteLine(DateTime.Now.ToString(thaiCulture));
        DateTimeFormatInfo thaiDateTimeFormat = thaiCulture.DateTimeFormat;
        thaiDateTimeFormat.Calendar = new GregorianCalendar();
        Console.Out.WriteLine(DateTime.Now.ToString(thaiCulture));

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.

ゃ懵逼小萝莉 2024-10-14 20:05:27

由于您正在修改现有区域性(替换),因此您无法删除日历,但可以对它们重新排序:

var carib = new CultureAndRegionInfoBuilder("th-TH",
                                            CultureAndRegionModifiers.Replacement);
carib.AvailableCalendars = new Calendar[] { new GregorianCalendar(),
                                            new ThaiBuddhistCalendar() };
carib.Register();

由于它是替换区域性,因此在开始新流程之前您不会看到效果。

Since you are modifying an existing culture (replacement) you cannot remove calendars, but you can reorder them:

var carib = new CultureAndRegionInfoBuilder("th-TH",
                                            CultureAndRegionModifiers.Replacement);
carib.AvailableCalendars = new Calendar[] { new GregorianCalendar(),
                                            new ThaiBuddhistCalendar() };
carib.Register();

Since it is a replacement culture, you won't see the effect until you start a new process.

乞讨 2024-10-14 20:05:27

如果不先删除现有文化,则无法更改它:

CultureAndRegionInfoBuilder.UnRegister("th-TH");

You can't change an existing Culture without removing it first:

CultureAndRegionInfoBuilder.UnRegister("th-TH");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文