Search code examples
asp.netdatetimecurrentculture

Manually set Culture Info Year Time Pattern


I would like to ask if it is a good coding practice to manually set the YearMonthPattern of the CurrentCulture? My problem is I set the current culture to Invariant, and the YearMonthPattern changed.

What I did is just added the code to set the YearMonthPattern just after setting the Cultures.

//Set Cultures
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(127);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(127);
//Set Year Month Pattern
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.YearMonthPattern = "MMMM, yyyy";

Solution

  • I can't see anything wrong with it. It's just that it might not be conform to the actual culture pattern but if that's how you want years to be displayed it is OK.