K
kilaen
I have this method that converts dates from a culture of origin to a
destination culture. It's not working as intended, hopefully someone
can enlighten me and tell me what I'm doing wrong. I've included the
code, the values being passed in, and the output. Thanks in advance!
value = "01/04/2007 12:30:48"
selected = {en-GB}
origin = {en-GB}
to = {en-US}
result = {1/4/2007 12:30:48 PM}
I expected to see: {4/1/2007 12:30:48PM}
public static DateTime ConvertDateTime(string value, CultureInfo
selected, CultureInfo origin, CultureInfo to)
{
DateTime result;
try
{
result = DateTime.Parse(value, to);
}
catch (Exception)
{
result = DateTime.Parse(value, selected);
}
return result;
}
destination culture. It's not working as intended, hopefully someone
can enlighten me and tell me what I'm doing wrong. I've included the
code, the values being passed in, and the output. Thanks in advance!
value = "01/04/2007 12:30:48"
selected = {en-GB}
origin = {en-GB}
to = {en-US}
result = {1/4/2007 12:30:48 PM}
I expected to see: {4/1/2007 12:30:48PM}
public static DateTime ConvertDateTime(string value, CultureInfo
selected, CultureInfo origin, CultureInfo to)
{
DateTime result;
try
{
result = DateTime.Parse(value, to);
}
catch (Exception)
{
result = DateTime.Parse(value, selected);
}
return result;
}