Invariant culture

We are creating an application that will be sent worldwide, when importing and exporting files of different formats.

We must use Invariant Culture for these standard files.

However, the invariant culture is similar to the EN-US culture, and not to standard international literature.

Saying, I would like to change at least the date format for this culture. But the following code just throws exceptions:

CultureInfo format = System.Globalization.CultureInfo.InvariantCulture; format.DateTimeFormat.FullDateTimePattern = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"; return format; 

What would be the correct way to create an IFormatProvider that formats any variable but has an international way of writing dates?

+4
source share
2 answers

An invariant culture is simply such that it is invariant. You cannot change it.

This culture is for .NET applications that need to store data in such a way that they are transferred between cultures.

It is not assumed that users will be displayed or should care about the format that this data accepts, it must always be converted to their specific culture before viewing the data.

How much could you do if you really wanted this DateTime format to start defining a new culture (perhaps based on a culture of invariants, if you want).

 var myStandardCulture = (CultureInfo)System.Globalization.CultureInfo.InvariantCulture.Clone(); myStandardCulture.DateTimeFormat.FullDateTimePattern = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"; return myStandardCulture; 

The disadvantage of defining your own culture is that other .NET applications that try to read your files will also need to talk about all your new culture rules, and not just accept the InvariantCulture rules built into .NET.

+7
source

There really is no “standard” way to write ... this is not what Invariant Culture means. The default behavior of most format methods is to use the cultural settings of the underlying operating system to format the date, time and numbers in a way that is most suitable for those who use a particular computer ... i.e. at runtime.

Try logging into the control panel on the development computer and change the localization settings. For example, in some cultures they use. as a thousands separator and as a decimal separator.

Forcing the “one international” way of doing things will be confusing because they are not used to seeing what we consider standard on a daily basis.

Dates are another good example of confusion, since many areas of the world standardize DD-MM-YYYY instead of MM-DD-YYYY, as in our country.

+1
source

Source: https://habr.com/ru/post/1397080/


All Articles