How to use Long Time ("T") Format Specifier
Description
The "T" format is defined by a specific culture's DateTimeFormatInfo.LongTimePattern property. For example, the custom format string for the invariant culture is "HH:mm:ss".
The following object properties control the format.
- LongTimePattern
- TimeSeparator
- AMDesignator
- PMDesignator
Example
The following example uses the "T" format specifier to display a date and time value.
//from w w w. j a v a 2 s .co 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("T",CultureInfo.CreateSpecificCulture("en-us")));
Console.WriteLine(date1.ToString("T",CultureInfo.CreateSpecificCulture("es-ES")));
}
}
The code above generates the following result.