Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Convert.ToString Method (DateTime)

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

Namespace:  System
Assemblies:   System.Runtime.Extensions (in System.Runtime.Extensions.dll)
  mscorlib (in mscorlib.dll)

public static string ToString(
	DateTime value
)

Parameters

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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft