DateTime dt = DateTime.Now; string displayedTime = dt.ToString("hh:mm:ss tt"); string displayedHour = dt.Hour.ToString("00"); string displayedHourVariant = dt.Hour.ToString().PadLeft(2, "0"); // the same
string[] customFmts = {"h:mm:ss.ff t", "d MMM yyyy", "HH:mm:ss.f", "dd MMM HH:mm:ss", @"\Mon\t\h\: M", "HH:mm:ss.ffffzzz" }; // Output date and time using each custom format string. foreach (string customFmt in customFmts) Console.WriteLine("'{0}': {1}", customFmt, dateValue.ToString(customFmt));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)