The LocalTime
type supports the following patterns:
The following standard patterns are supported:
t
: Short format pattern.
This is the short time pattern as defined by the culture's DateTimeFormatInfo.ShortTimePattern
.
For example, in the invariant culture this is "HH:mm".T
: Long format pattern.
This is the long time pattern as defined by the culture's DateTimeFormatInfo.LongTimePattern
.
For example, in the invariant culture this is "HH:mm:ss". This is the default format pattern.r
: Round-trip pattern.
This always uses a pattern of "HH:mm:ss.FFFFFFF", but with the culture-specific time separator.The following custom format pattern characters are supported for local times. See custom pattern notes for general notes on custom patterns, including characters used for escaping and text literals.
Character | Meaning | Example |
H or HH |
The hour of day in the 24-hour clock; a value 0-23.
Note that when parsing local date/time values, a value of |
7.30am: H:mm => 7:30 7.30pm: H:mm => 19:30 7.30am: HH:mm => 07:30 7.30pm: HH:mm => 19:30
|
h or hh |
The hour of day in the 12-hour clock; a value 1-12. When parsing, if no am/pm designator is specified, the parsed value is in the morning. |
7.30am: h:mm => 7:30 7.30pm: h:mm => 7:30 7.30am: hh:mm => 07:30 7.30pm: hh:mm => 07:30
|
m or mm |
Number of minutes within the hour. mm is zero-padded; m is not.
|
5 minutes: m:ss => 5:00 5 minutes: mm:ss => 05:00
|
s or ss |
Number of seconds within the minute. ss is zero-padded; s is not.
|
5 seconds: s.fff => 5.000 5 seconds: ss.fff => 05.000
|
f , ff ... up to fffffff |
The fractional second part of the time, using exactly the specified number of characters (up to 7, for a representation accurate to a tick). |
1 second, 340 milliseconds: s.fff => 1.340 1 second, 340 milliseconds: s.ff => 1.34 1 second, 340 milliseconds: s.f => 1.3 |
F , FF ... up to FFFFFFF |
The fractional second part of the offset, using at most the specified number of characters (up to 7, for a representation accurate to a tick). Trailing digits are truncated towards zero, and trailing insignificant zeroes are truncated. If this comes after a period (".") and the value is zero, the period is also truncated. |
1 second, 340 milliseconds: s.FFF => 1.34 1 second, 340 milliseconds: s.FF => 1.34 1 second, 340 milliseconds: s.F => 1.3 Exactly 1 second: s.F => 1 |
t or tt |
The culture-specific AM/PM designator, either in full (for tt ) or just the first character
(for t ).
|
13:10: h:mm tt => 1:10 PM
13:10: h:mm:sst => 1:10:00P
|
. |
This is always a period ("."); not a culture-sensitive decimal separator as one might expect. This follows the example of other standard libraries, however odd it may appear. The only difference between a period and any other literal character is that when followed by a series of "F" characters, the period will be removed if there are no fractional seconds. |
12 seconds, 500 milliseconds (en-US): ss.FFF => 12.5 12 seconds, 500 milliseconds (fr-FR): ss.FFF => 12.5
|
; |
This is always formatted as a period, but can parse either a period or a comma. In all other respects it behaves as the period custom specifier. The purpose of this specifier is to properly parse ISO-8601 times, where a comma is allowed as the separator for subsecond values. |
Pattern ss;fff parses 53,123 and 53.123
identically.
|
: |
The time separator for the format provider; colon in the invariant culture. | HH:mm => 07:30 |