I'm working with an application that provides date times strings containing timezones. Here is an example:
21/07/2011 10:42 AM BST
When I parse this using DateTime.Parse
, including specifying the British locale...
[TestMethod]
public void ParseDateStringWithBSTTimeZone()
{
string dateString = "21/07/2011 10:42 AM BST";
var date = DateTime.Parse(dateString, CultureInfo.CreateSpecificCulture("en-GB"));
Assert.AreEqual(new DateTime(2011, 7, 21, 9, 42, 0), date);
}
I get the following error:
System.FormatException: The string was not recognized as a valid DateTime. There is an unknown word starting at index 20.
How can I parse this date time string? Doesn't .NET DateTime library support dates with this format?