Search code examples
c#datetimeiso8601

Date and time format conversion in C#


I have date/time format, for example:

"2012-06-28T08:26:57Z"

What kind of date/time format is that and how can it be converted into the following format, using DateTime format in C#.:

"8/24/2012 4:09:17 AM"

Solution

  • You can do this:

    string input = "2012-06-28T08:26:57Z";
    var dt = DateTime.Parse(input);
    string output = dt.ToString(@"MM/dd/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
    

    For the meaning of each part of your input string, take a look at this link: http://www.w3.org/TR/NOTE-datetime