How to use General Date Long Time ("G") Format Specifier
Description
The "G" format combines the short date ("d") and long time ("T") patterns, separated by a space.
The following DateTimeFormatInfo properties control the format.
- ShortDatePattern
- LongTimePattern
- DateSeparator
- TimeSeparator
- AMDesignator
- PMDesignator
Example
The following example uses the "G" format specifier to display a date and time value.
/*w w w . ja v a 2s . co m*/
using System;
using System.Globalization;
class MainClass
{
public static void Main()
{
DateTime date1 = new DateTime(2012, 4, 10, 6, 30, 0);
Console.WriteLine(date1.ToString("G", DateTimeFormatInfo.InvariantInfo));
Console.WriteLine(date1.ToString("G", CultureInfo.CreateSpecificCulture("en-us")));
Console.WriteLine(date1.ToString("G", CultureInfo.CreateSpecificCulture("nl-BE")));
}
}
The code above generates the following result.