System Namespace DateTime Structure
Converts the value of this instance to its equivalent string representation using the specified format.
[ VB ]
<Serializable>
Overloads Public Function ToString ( _
ByVal format As String _
) As String
[ C# ]
[ Serializable ]
public string ToString (
string format
);
[ C++ ]
[ Serializable ]
public: String* ToString (
String* format
);
[ JScript ]
public Serializable
function ToString (
format : String
) : String;
- format
- A format string.
A string representation of value of this instance as specified by format.
Exception Type |
Condition |
FormatException |
The length of format is 1, and it is not one of the format specifier characters defined for DateTimeFormatInfo.
-or-
format does not contain a valid custom format pattern.
|
The format parameter should contain either a format specifier character or a custom format pattern. For more information, see the summary page for System.Globalization.DateTimeFormatInfo.
If format is a null reference ( Nothing in Visual Basic ) or an empty string, the general format specifier, 'G', is used.
This method uses formatting information derived from the current culture. For more information, see CurrentCulture.
The below demonstrates using the different ways of formatting a DateTime instance using patterns derived from the DateTimeFormatInfo used by the current culture setting.
Show me
DateTime Members DateTime.ToString Overload List DateTimeFormatInfo CultureInfo