13.2.3 Time Values

Time values are formatted in a manner similar to date values. In this case the key letters are h, m, and s. The table below shows how the key letters are used.

String Description

h One or two digit hour, 12 hour cycle (blank fill).

hh Two digit hour, 12 hour cycle (zero fill).

H One or two digit hour, 24 hour cycle (blank fill).

HH Two digit hour, 24 hour cycle (zero fill).

m Not valid (use \m for m)

mm Two digit minute (zero fill).

s Not valid (use \s for s)

ss Two digit seconds (zero fill).

When the time value is converted, these key letters are replaced with the described values. All other characters are inserted as literal text. In addition to key letter replacement, time values also use two specifiers: the first for times before noon, the second for times after noon. If only one specifier is present, it is used for all times. The examples below show the result of formatting a time of 9:23:52 AM and 9:23:52 PM.

Format Result

AM PM

hh:mm:ss 09:23:52 09:23:52

HH:mm:ss 09:23:52 21:23:52

h:mm AM;h:mm PM 9:23 AM 9:23 PM

H:mm AM;H:mm PM 9:23 AM 21:23 PM

H\h.mm.ss 9h.23.52 21h.23.52

h\hr\s, mm\min\s 9hrs, 23mins 9hrs, 23mins

ss;mm 52 23

Note the use of the escape character (\) to insert literal text into the formatted text. Like dates, it is possible to create confusing formats (see first and last examples). If only one specifier is used for time values, it should use the 24 hour cycle characters (H or HH). When using two specifiers be sure they indicate the 12 hour cycle (third example).