General Date Long Time ("G") Format Specifier in C#

CsharpProgrammingServer Side Programming

The General Date Long Time standard format specifier is a combination of the short date ("d") and long time ("T") patterns, separated by a space.

Set the date −

DateTime dt = new DateTime(2018, 1, 3, 3, 45, 20);

Now, use the ToString() method and DateTimeFormatInfo.

dt.ToString("G", DateTimeFormatInfo.InvariantInfo)

Example

 Live Demo

using System;
using System.Globalization;
class Demo {
   static void Main() {
      DateTime dt = new DateTime(2018, 1, 3, 3, 45, 20);
      Console.WriteLine(dt.ToString("G",
      DateTimeFormatInfo.InvariantInfo));
   }
}

Output

01/03/2018 03:45:20
raja
Published on 11-Sep-2018 15:52:56
Advertisements