C# DateTime ToString()
Description
DateTime ToString()
converts the value of the current
DateTime object to its equivalent string representation.
Syntax
DateTime.ToString()
has the following syntax.
public override string ToString()
Returns
DateTime.ToString()
method returns A string representation of the value of the current DateTime object.
Example
The following example demonstrates the ToString method.
using System;//from w w w .j a va 2s . c o m
class Sample
{
public static void Main()
{
DateTime myDateTime = new System.DateTime(2001, 5, 16, 3, 2, 15);
Console.WriteLine("Long date string: \"{0}\"\n", myDateTime.ToString());
}
}
The code above generates the following result.