I’m trying to make my application handle some conversions of DateTimes from string. In order to handle varying culture, I specify the culture I want the conversion to use. I thought that had me covered, but I discovered that you can change specific elements of how that system defines “en-US”, like the long and short date patterns.
In those cases, the code below does not work, when the dates being parsed are in MM/dd/yyyy format.
CultureInfo c = new CultureInfo("en-US");
string[] permissions = Regex.Split(permissionData, @"\r\n");
foreach (string permission in permissions)
{
string[] details = permission.Split(',');
this.Add(new WPermission()
{
WRegion = Convert.ToInt32(details[0],c),
StartDate = Convert.ToDateTime(details[1],c),
EndDate = Convert.ToDateTime(details[2],c)
});
}
My question is: Is there a way to access the default definition of “en-US”, and load that instead of the user defined version, or am I relegated to something like ParseExact? As a note, I cannot control the source format of the string I am parsing, it’s third party.
Thanks!
You can use CultureInfo.InvariantCulture, which is associated with English, but ignores regional information and user customizations.