I'm using .NET 3.5 and I have a date that comes in as string in the following format:
Tue Jan 20 20:47:43 GMT 2009
First question, what is the name of that format? Second question, what's the easiest and clearest way to convert this string into a datetime? I would love to be able to use a .net API/Helper method if possible.
Edit: I forgot to mention that I've already tried using DateTime.Parse and Convert.ToDateTime. None of those worked.
You can use the DateTime.TryParseExact() method with a suitable format string. See here
EDIT: Try something like this:
DateTime dt;
System.Globalization.CultureInfo enUS = new System.Globalization.CultureInfo("en-US");
if ( DateTime.TryParseExact( "Tue Jan 20 20:47:43 GMT 2009", "ddd MMM dd H:mm:ss \"GMT\" yyyy", enUS, System.Globalization.DateTimeStyles.NoCurrentDateDefault , out dt ))
{
Console.WriteLine(dt.ToString() );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With