Mega Code Archive

 
Categories / C# Book / 02 Essential Types
 

0270 DateTime ToString format

DateTime ToString method formats the result as a short date followed by a long time. using System; using System.Text; class Sample { public static void Main() { DateTime thisYear = new DateTime(2007, 1, 1); Console.WriteLine(thisYear.ToString()); } } The output: 1/1/2007 12:00:00 AM