How to use General Date Short Time ("g") Format Specifier
Description
The "g" format combines the short date ("d") and short time ("t") patterns, separated by a space.
The following DateTimeFormatInfo properties control the format.
- ShortDatePattern
- ShortTimePattern
- DateSeparator
- TimeSeparator
- AMDesignator
- PMDesignator
Example
The following example uses the "g" format specifier to display a date and time value.
/*from w w w. ja v a 2 s .c o m*/
using System;
using System.Globalization;
class MainClass
{
public static void Main()
{
DateTime date1 = new DateTime(2008, 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("fr-BE")));
}
}
The code above generates the following result.