Possible Duplicate:
Parse string to DateTime in C#
I am getting date and time returned from an API as a string in the following format:
Mon Aug 13 15:04:51 -0400 2012
Does anyone have experience with how I can turn this into a DateTime?
Possible Duplicate:
Parse string to DateTime in C#
I am getting date and time returned from an API as a string in the following format:
Mon Aug 13 15:04:51 -0400 2012
Does anyone have experience with how I can turn this into a DateTime?
How about
DateTime dt = DateTime.ParseExact("Mon Aug 13 15:04:51 -0400 2012",
"ddd MMM dd HH:mm:ss K yyyy",
CultureInfo.InvariantCulture)
You should read about Custom Date and Time Format Strings
K for this: "ddd MMM dd HH:mm:ss K yyyy"5:30 + 4 = 9:30, so 9 and a half hours of difference. That's exactly the amount of time added to get your result. Make sense? In other words, 15:04 in central Brazil is the same point in time as 00:34 in India (not taking DST into account).13/08/2012 15:04:51CultureInfo.InvariantCulture when formatting, try pt-Br.Have a look at the DateTime.Parse method.
Or if you are not sure that the parsing will succeed, use the DateTime.TryParse method.
For unconventional date and time strings use the DateTime.ParseExact method.
Check these two links, I think they will be very useful to you: