Convert::ToDateTime Method (Object, IFormatProvider)
Converts the value of the specified object to a DateTime object, using the specified culture-specific formatting information.
Assembly: mscorlib (in mscorlib.dll)
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::DateTimeThe date and time equivalent of the value of value, or the date and time equivalent of DateTime::MinValue if value is nullptr.
| 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.
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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.