|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Need Help: DateTime.Parse CultureInfo Problemdestination 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; } kil***@gmail.com wrote:
> I have this method that converts dates from a culture of origin to a No, it does not. It parses the text representation of a date from one of > destination culture. two cultures into a DateTime value. A DateTime value is culture neutral. > It's not working as intended, hopefully someone You are parsing the date using the en-US culture. What culture have you > 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} used to create the textual representation of the result? Show quote > 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; > } > |
|||||||||||||||||||||||