Converting date formats

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

Hi,

What is the easiest way to create a DateTime object from
a string of the format:
1998-06-22T13:00

(i.e. 22nd June 1998, 1pm)

I've tried splitting the string up, but this seems rather
complicated. Is there a simpler way to do this?

Regards,

Adam.
 
Just use the DateTime.ParseExact method to create a DateTime object with
your particular format.

DateTime dt = DateTime.ParseExact("1998-06-22T13:00", @"yyyy-MM-dd\THH:mm",
System.Globalization.DateTimeFormatInfo.InvariantInfo);
-Noah Coad
Microsoft MVP & MCP [.NET/C#]
 
Back
Top