简体   繁体   中英

Change windows Culture Settings or define new using C#

Can i update the windows culture settings permanently using C#?

Or can i define a new culture in windows using C#?

If yes, then please also provide the code of C# or VB.Net.

I know how to change the culture settings for a project.

Thanks in advance.

Even if you want to change the culture setting, you can still run in formatting problems. If the user changes the settings of the culture in windows you still do not know what formatting rules (formatter) you can expect. For example changing the culture before parsing a datetime is a bad practice. If you need to parse a specific formatting, you can better make a formatter like:

dateString = "Sun 15 Jun 2008 8:30 AM -06:00";
format = "ddd dd MMM yyyy h:mm tt zzz";
try {
    result = DateTime.ParseExact(dateString, format, provider);
    Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException) {
    Console.WriteLine("{0} is not in the correct format.", dateString);
}

Good practice is to assume that the users computer has the right formatting for the specific user. Then the user can give the values in the same format as any other program he uses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM