DateTime format
-
Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.
-
Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.
Use the "g" or "G" for general date. The lower case g will give you to minutes as you asked (short date and short time). If you use capital G, you also get seconds (short date and long time. If you do not want the AM/PM notation, use a custom format mask "M/d/yyyy m:h". Note, capitalization is important. Use M for month and m for minutes. If you use h you get 12 hour notation, if you use H, you get 24 hour notation. David
-
Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.
-
Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.
If you are calling the ToString method of the DateTime object, you would want to use the following: public void sample() { // Create a new DateTime instance set to // 9/1/2006 7:22 PM DateTime d = new DateTime(2006, 9, 1, 14, 22, 0); Console.WriteLine(d.ToString(@"MM/dd/yyyy HH:mm")); }