Well,
This is a string I get from a web service:
"Tuesday, March 30, 2010 10:45 AM"
and I need to convert it to a DateTime.
Do you know a simple way to achieve this?
Thanks,
Well,
This is a string I get from a web service:
"Tuesday, March 30, 2010 10:45 AM"
and I need to convert it to a DateTime.
Do you know a simple way to achieve this?
Thanks,
string strDateTime = "Tuesday, March 30, 2010 10:45 AM";
DateTime myDateTime = DateTime.Parse(strDateTime);
That's in the "F" format.
It should be parsed easily by
DateTime.Parse( s );
or by DateTime.ParseExact( string s, string format, IFormatProvider provider );
as
DateTime.ParseExact( s, "F", CultureInfo.InvariantCulture );
Parse may or may not work depending on your Culture settings.
I would recommend using the InvariantCulture, unless you can be sure your computer's culture is set to a culture that works ("en") and not one that fails ("ar").
DateTime.Parse("Tuesday, March 30, 2010 10:45 AM", CultureInfo.InvariantCulture )
Not as simple but safer.
DateTime dts;
string strDateTime = "Tuesday, March 30, 2010 10:45 AM";
if(!DateTime.tryParse(strDateTime, out dts))
Console.WriteLine("not a date!");