This post shows you how to format DateTime using DateTime.Now.ToString() method.
There are different datetime Formats as menctioned below...
There are different datetime Formats as menctioned below...
DateTime dt = new DateTime.Now.ToString(); // jan-23-2012
gives an output as Monday, January 23, 2012
More Examples :
dt.ToString("dd-MM-yyyy"); // Indian Date Format 23-01-2012
dt.ToString("dd-MM-yyyy HH:mm:ss"); // Indian Date and Time 23-01-2012 23:35:07
dt.ToString("dd-MM-yyyy HH:mm tt"); // Indian Date and Time 23-01-2012 23:35 PM
dt.String.Format("y yy yyy yyyy",dt);// "2 12 012 2012" year dt.String.Format("M MM MMM MMMM",dt);// "1 01 Jan January" month dt.String.Format("d dd ddd dddd",dt);// "23 23 Mon Monday" day dt.String.Format("h hh H HH", dt);// "4 04 16 16" hour 12/24 dt.String.Format("m mm", dt);// "5 05" minute dt.String.Format("s ss", dt);// "7 07" second dt.String.Format("f ff fff ffff",dt);// "1 12 123 1230" sec.fraction dt.String.Format("F FF FFF FFFF",dt);// "1 12 123 123" without zeroes dt.String.Format("t tt", dt);// "P PM" A.M. or P.M. dt.String.Format("z zz zzz", dt);// "-6 -06 -06:00" time zone