- formats
An array containing the format structures to apply to the converted DateTime. Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.
- s
The string to convert.
- formats
An array containing the format structures to apply to the converted DateTime. Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.
![]()
A DateTime equivalent of the string.
Type Reason ArgumentNullException s is a null reference. FormatException s or an element of formats is string.Empty.
-or-
s does not contain a date and time that corresponds to any of the elements of formats.
The following example converts a string to a DateTime and writes the result to the console.
C# Example
using System;
using System.Xml;
public class App {
public static void Main() {
String someDate = "1966-09-19T03:45:11Z";
String[] datetimeFormats = new String[]
{"HH:mm:ss", "yyyy-MM-ddTHH:mm:ssZ"};
DateTime dateTime =
XmlConvert.ToDateTime(someDate, datetimeFormats);
Console.WriteLine( "{0}", dateTime.ToString() );
}
}
The output is
9/18/1966 8:45:11 PM