XmlConvert.ToDateTime Method    
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| ToDateTime(String) | 
							 
		Obsolete.
	 
	
		Obsolete.
	 
					 | 
        	
| ToDateTime(String, String) | |
| ToDateTime(String, String[]) | |
| ToDateTime(String, XmlDateTimeSerializationMode) | 
						 Converts the String to a DateTime using the XmlDateTimeSerializationMode specified.  | 
        	
ToDateTime(String)
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
Caution
Use XmlConvert.ToDateTime() that accepts an XmlDateTimeSerializationMode instead.
Caution
Use XmlConvert.ToDateTime() that takes in XmlDateTimeSerializationMode
public:
 static DateTime ToDateTime(System::String ^ s);
	[System.Obsolete("Use XmlConvert.ToDateTime() that accepts an XmlDateTimeSerializationMode instead.")]
public static DateTime ToDateTime(string s);
	[System.Obsolete("Use XmlConvert.ToDateTime() that takes in XmlDateTimeSerializationMode")]
public static DateTime ToDateTime(string s);
	public static DateTime ToDateTime(string s);
	[<System.Obsolete("Use XmlConvert.ToDateTime() that accepts an XmlDateTimeSerializationMode instead.")>]
static member ToDateTime : string -> DateTime
	[<System.Obsolete("Use XmlConvert.ToDateTime() that takes in XmlDateTimeSerializationMode")>]
static member ToDateTime : string -> DateTime
	static member ToDateTime : string -> DateTime
	Public Shared Function ToDateTime (s As String) As DateTime
	Parameters
- s
 - String
 
The string to convert.
Returns
A DateTime equivalent of the string.
- Attributes
 
Exceptions
s is null.
s is an empty string or is not in the correct format.
Remarks
Note
The XmlConvert.ToDateTime(String) method is obsolete in the 2.0 version of the .NET Framework and has been replaced by the XmlConvert.ToDateTime(String, XmlDateTimeSerializationMode) method.
Applies to
ToDateTime(String, String)
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
public:
 static DateTime ToDateTime(System::String ^ s, System::String ^ format);
	public static DateTime ToDateTime(string s, string format);
	static member ToDateTime : string * string -> DateTime
	Public Shared Function ToDateTime (s As String, format As String) As DateTime
	Parameters
- s
 - String
 
The string to convert.
- format
 - String
 
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
s is null.
s or format is String.Empty
-or-
s does not contain a date and time that corresponds to format.
Applies to
ToDateTime(String, String[])
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
public:
 static DateTime ToDateTime(System::String ^ s, cli::array <System::String ^> ^ formats);
	public static DateTime ToDateTime(string s, string[] formats);
	static member ToDateTime : string * string[] -> DateTime
	Public Shared Function ToDateTime (s As String, formats As String()) As DateTime
	Parameters
- s
 - String
 
The string to convert.
- formats
 - String[]
 
An array containing the format structures to apply to the converted DateTime. Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.
Returns
A DateTime equivalent of the string.
Exceptions
s is null.
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.
Remarks
This method allows multiple formats for the string to be validated against.
Applies to
ToDateTime(String, XmlDateTimeSerializationMode)
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
- Source:
 - XmlConvert.cs
 
Converts the String to a DateTime using the XmlDateTimeSerializationMode specified.
public:
 static DateTime ToDateTime(System::String ^ s, System::Xml::XmlDateTimeSerializationMode dateTimeOption);
	public static DateTime ToDateTime(string s, System.Xml.XmlDateTimeSerializationMode dateTimeOption);
	static member ToDateTime : string * System.Xml.XmlDateTimeSerializationMode -> DateTime
	Public Shared Function ToDateTime (s As String, dateTimeOption As XmlDateTimeSerializationMode) As DateTime
	Parameters
- dateTimeOption
 - XmlDateTimeSerializationMode
 
One of the enumeration values that specify whether the date should be converted to local time or preserved as Coordinated Universal Time (UTC), if it is a UTC date.
Returns
A DateTime equivalent of the String.
Exceptions
s is null.
dateTimeOption is null.
s is an empty string or is not in a valid format.