parsing odd date formats

  • Thread starter Thread starter Jon Sequeira
  • Start date Start date
J

Jon Sequeira

I'm looking for a clean way of parsing a date format such as these (both
examples show today's date):

20030922
20030918T10:34:44

Date.Parse won't swallow these. I'm unfamiliar with the IFormatProvider
interface-- can I use this to quickly parse a date if I know what the format
will be?

Any insights appreciated.

Thanks.

Jon
 
Use ParseExact to specify the actual formatting that you want.

Console.WriteLine(DateTime.ParseExact("20020923", "yyyyMMdd", null));
Console.WriteLine(DateTime.ParseExact("20030918T10:34:44",
"yyyyMMddThh:mm:ff", null));
 
Back
Top