Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Convert::ToDateTime Method (Object^, IFormatProvider^)

 

Converts the value of the specified object to a DateTime object, using the specified culture-specific formatting information.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public:
static DateTime ToDateTime(
	Object^ value,
	IFormatProvider^ provider
)

Parameters

value
Type: System::Object^

An object that implements the IConvertible interface.

provider
Type: System::IFormatProvider^

An object that supplies culture-specific formatting information.

Return Value

Type: System::DateTime

The date and time equivalent of the value of value, or the date and time equivalent of DateTime::MinValue if value is null.

Exception Condition
FormatException

value is not a valid date and time value.

InvalidCastException

value does not implement the IConvertible interface.

-or-

The conversion is not supported.

The return value is the result of invoking the IConvertible::ToDateTime method of the underlying type of value.

provider enables the user to specify culture-specific conversion information about the contents of value. For example, if value is a String that represents a date, provider could supply culture-specific information about the notation used to represent that date. provider is involved in the conversion of value if the runtime type of value is a String, or if value is a user-defined type whose IConvertible::ToDateTime implementation makes use of provider. If the runtime type of value is String and provider is null, the CultureInfo object that represents the current thread culture is used.

The following example defines a custom format provider, CustomProvider, whose GetFormat method outputs a message to the console that it has been invoked, and then returns the DateTimeFormatInfo object of the culture whose name was passed as a parameter to its class constructor. Each of these CustomProvider objects is used to convert the elements in an object array to date and time values. The output indicates that the CustomProvider object is used in the conversion only when the type of the value parameter is a String.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: