Windows apps
Collapse the table of content
Expand the table of content
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.ToString Method (DateTime)


Converts the value of the specified DateTime to its equivalent string representation.

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

public static string ToString(
	DateTime value


Type: System.DateTime

The date and time value to convert.

Return Value

Type: System.String

The string representation of value.

This implementation is identical to DateTime.ToString(). It uses the formatting conventions of the current culture and the "G" format specifier to convert a DateTime value to its string representation.

The following example converts each element in an array of a DateTime value to a String value.

DateTime[] dates = { new DateTime(2009, 7, 14), 
                     new DateTime(1, 1, 1, 18, 32, 0), 
                     new DateTime(2009, 2, 12, 7, 16, 0) };
string result;

foreach (DateTime dateValue in dates)
   result = Convert.ToString(dateValue);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                        dateValue.GetType().Name, dateValue,
                        result.GetType().Name, result);
// The example displays the following output:
//    Converted the DateTime value 7/14/2009 12:00:00 AM to a String value 7/14/2009 12:00:00 AM.
//    Converted the DateTime value 1/1/0001 06:32:00 PM to a String value 1/1/0001 06:32:00 PM.
//    Converted the DateTime value 2/12/2009 07:16:00 AM to a String value 2/12/2009 07:16:00 AM.

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