I store some DateTime in a CSV log with:
DateTime.Now.ToString(\"MM/dd/yyyy hh:mm:ss.fff\")
When I try to read it I found something like:
You should use this method to parse your string. You would have to make a class, imlementing IFormatProvider, but if you want to use a custom DateTime format, it's the best method I can think of.
You can use DateTime.ParseExact:
string format = "MM/dd/yyyy hh:mm:ss.fff";
DateTime d = DateTime.ParseExact("05/15/2012 10:09:28.650",
format,
System.Globalization.CultureInfo.InvariantCulture);
Standard Date and Time Format Strings
use DateTime.ParseExact with specifying the format
String dateStr=DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff");
DateTime date = DateTime.ParseExact(dateStr,"MM/dd/yyyy hh:mm:ss.fff",System.Globalization.CultureInfo.InvariantCulture);