Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Culture is not supported. Parameter name: name US is an invalid culture identifier

I tried to use a ISO-3166 two letter country code to create my C# culture info object to format my datetime objects according to the locale.

If I try:

var cultureInfo = new CultureInfo("FR");

it works fine, if I try:

var cultureInfo = new CultureInfo("US");

it throws an exception:

Culture is not supported. Parameter name: name US is an invalid culture identifier.

The funny thing is that "US" is a valid ISO-3166 country code.

like image 351
Gianluca Ghettini Avatar asked Dec 18 '22 20:12

Gianluca Ghettini


1 Answers

From CultureInfo(string) constructor documentation;

For a list of predefined culture names, see the National Language Support (NLS) API Reference

Also from CultureInfo.TwoLetterISOLanguageName Property

For example, the two-letter abbreviation for English is en.

There is no US defined but there is en (if you really have to use two letter name) which you can use it. All of them defined in ISO 639-1 standard.

var cultureInfo = new CultureInfo("en");
like image 114
Soner Gönül Avatar answered Dec 28 '22 23:12

Soner Gönül