DateTime::ToString Method
Converts the value of the current DateTime object to its equivalent string representation.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Return Value
Type: System::StringA string representation of the value of the current DateTime object.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The date and time is outside the range of dates supported by the calendar used by the current culture. |
The value of the current DateTime object is formatted using the general date and time format specifier ('G').
This method uses formatting information derived from the current culture. In particular, it combines the custom format strings returned by the ShortDatePattern and LongTimePattern properties of the DateTimeFormatInfo object returned by the Thread.CurrentThread.CurrentCulture.DateTimeFormat property. For more information, see CultureInfo::CurrentCulture. Other overloads of the ToString method enable you to specify the culture whose formatting to use and to define the output pattern of the DateTime value.
Platform Notes
Silverlight for Windows Phone
The ToString() method returns the string representation of the date and time in the calendar used by the current culture. If the value of the current DateTime instance is earlier than Calendar::MinSupportedDateTime or later than Calendar::MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException. The following example provides an illustration. It attempts to format a date that is outside the range of the HijriCalendar class when the current culture is Arabic (Syria).
The following example illustrates how the string representation of a DateTime value returned by the ToString() method depends on the thread current culture. It changes the current thread culture from en-US to fr-FR to ja-JP. and in each case calls the ToString() method to return the string representation of a date and time value using that culture.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.