These expressions may be used to control how time is displayed using the format attribute of the clock element:
Expression | Output |
---|---|
h | The hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | The hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
H | The hour without a leading zero (0 to 23, even with AM/PM display) |
HH | The hour with a leading zero (00 to 23, even with AM/PM display) |
m | The minute without a leading zero (0 to 59) |
mm | The minute with a leading zero (00 to 59) |
s | The whole second, without any leading zero (0 to 59) |
ss | The whole second, with a leading zero where applicable (00 to 59) |
z | The fractional part of the second, to go after a decimal point, without trailing zeroes (0 to 999). Thus "s.z" reports the seconds to full available (millisecond) precision without trailing zeroes. |
zzz | The fractional part of the second, to millisecond precision, including trailing zeroes where applicable (000 to 999). |
AP or A | Use AM/PM display. |
ap or a | Use am/pm display. |
t | The timezone (for example "CEST") |
Any non-empty sequence of characters enclosed in single quotes will be included verbatim in the output string (stripped of the quotes), even if it contains formatting characters. Two consecutive single quotes ("''") are replaced by a single quote in the output. All other characters in the format string are included verbatim in the output string.
Formats without separators (e.g. "ddMM") are supported but must be used with care, as the resulting strings aren't always reliably readable (e.g. if "dM" produces "212" it could mean either the 2nd of December or the 21st of February).
Example format strings assuming the time is 14:13:09.042 and the system locale is en_US
Format | Result |
---|---|
hh:mm:ss.zzz | 14:13:09.042 |
h:m:s ap | 2:13:9 pm |
H:m:s a | 14:13:9 pm |
If the time is invalid, an empty string will be returned. If format is empty, the default format "hh:mm:ss" is used.