开发者

Change Default Calendar of CultureAndRegionInfoBuilder

I want to change the default calender of 'th-TH' culture from ThaiBuddhist to Gregorian and re开发者_如何转开发gister 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.

Please help. Thanx


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.


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.


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

CultureAndRegionInfoBuilder.UnRegister("th-TH");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜