C# Convert ToString(DateTime)
Description
Convert ToString(DateTime)
converts the value of the
specified DateTime to its equivalent string representation.
Syntax
Convert.ToString(DateTime)
has the following syntax.
public static string ToString(
DateTime value
)
Parameters
Convert.ToString(DateTime)
has the following parameters.
value
- The date and time value to convert.
Returns
Convert.ToString(DateTime)
method returns The string representation of value.
Example
The following example converts each element in an array of a DateTime value to a String value.
// w w w . ja v a2 s .c om
using System;
public class MainClass{
public static void Main(String[] argv){
DateTime[] dates = { new DateTime(2014, 7, 14),
new DateTime(1, 1, 1, 18, 32, 0),
new DateTime(2014, 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 code above generates the following result.