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


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020

153 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements