This topic has not yet been rated - Rate this topic

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
)

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.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.