tags:

views:

126

answers:

2

i want to convert this string into DateTime.

 Tue Aug 19 15:05:05 +0000 2008

I have tried the following code, but not getting the proper value.

string strDate = "Tue Aug 19 15:05:05 +0000 2008";
DateTime date;
DateTime.Parse(strDate,out date);
+6  A: 

Take a look at DateTime.Parse and DateTime.ParseExact.

Mark B
@Mark I was already doing that but not getting the proper values.
@Mark thats why i posted question on SO
Yes, I missed that when I first looked at your question, which is why I edited my answer to include `ParseExact`—but Darin's answer is much more comprehensive anyway.
Mark B
+8  A: 
DateTime date = DateTime.ParseExact(
    "Tue Aug 19 15:05:05 +0000 2008", 
    "ddd MMM dd HH:mm:ss zzz yyyy", 
    CultureInfo.InvariantCulture
);

For more safety use TryParseExact method:

string str = "Tue Aug 19 15:05:05 +0000 2008";
string format = "ddd MMM dd HH:mm:ss zzz yyyy";
DateTime date;
if (DateTime.TryParseExact(str, format, CultureInfo.InvariantCulture, 
    DateTimeStyles.None, out date))
{
    Console.WriteLine(date.ToString());
}
Darin Dimitrov
Nicely formatted to show the correlation between the actual data and the date time info string.
btlog
it helped me alot. Thanks dude.
What `zzz` stands for?
TheMachineCharmer
@The Machine Charmer: RTFM http://msdn.microsoft.com/en-us/library/bb301210.aspx
bzlm