System.Xml.XmlConvert.ToDateTime Method

Converts the string to a DateTime equivalent.

Syntax

public static DateTime ToDateTime (string s, string format)

Parameters

format
The format structure to apply to the converted DateTime. Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets. The string is validated against this format.
s
The string to convert.
format
The format structure to apply to the converted DateTime. Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets. The string is validated against this format.

Returns

A DateTime equivalent of the string.

Exceptions

TypeReason
ArgumentNullException s is a null reference.
FormatException

s or format is string.Empty .

-or-

s does not contain a date and time that corresponds to format.

Remarks

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0