Converts the date and time value of a specified DateTime to a String.
[Visual Basic] Overloads Public Shared Function ToString( _ ByVal dt As DateTime _ ) As String [C#] public static string ToString( DateTime dt ); [C++] public: static String* ToString( DateTime dt ); [JScript] public static function ToString( dt : DateTime ) : String;
A string value containing the date and time that the specified DateTime instance represents.
Exception Type | Condition |
---|---|
FormatException | If the general format ("G") string is used. |
The ToString method uses InvariantCulture as default. The output of ToString must be consumable by FromString.
An unexpected FormatException occurs while using the ToSring general format ("G) string when the general format DateTime string representation is not parsed correctly.
Note ToString is formatted using the invariant culture (see InvariantCulture).
Note ToString converts the date and time value of a specified DateTime to a string value, then formats the return value determined by the InvariantCulture For example, the English (United States) format is " mm/dd/yy hh:mm:ss
PP ", where:
DateTime Structure | DateTime Members | System Namespace | DateTime.ToString Overload List | String | DateTimeFormat | CultureInfo | Calendar | DateTimeFormatInfo