Formatting rule for the time-span (TimeSpan
) specifies the text (formatted) form of time-span. A properly created formatting rule allows bidirectional conversion between a text expression and a value of the TimeSpan
type without loss of information.
Formatting rule contains both constant items (e.g. separators inside the time-span) and individual time-span items. The time-span items must be in a mandatory order from the largest item (day) to the smallest item (millisecond). Each time-span item (day, hour, minute, etc.) has its own identifier (character: D, H, M, etc.).
The time-span item shall be indicated in the formatting rule by the percent sign %
, this distinguishes it from constant items (separators). This is followed by an optional number of characters (where the asterisk *
indicates the minimum required size with no zeros from the left, e.g., instead of 01.01.
it would be 1.1.
). This is followed by the mandatory identifier of time-span item.
For example: "%N%d/%H:%M:%S.%T"
Syntax of one time-span item: %[*|1-9]id
- The sign (+/-
character]. The number of characters 1
(default) displays + or - , while the number of characters 0
will display - or nothing.
- day (1-31
- hour (0-23
- minute (0-59
- second (0-59
- millisecond (0-999
digits]. The number of characters here means the precision after the decimal separator, so 1=tenths, 2=hundredths, and 3=thousandths.
The order of time-span items must be listed from the largest (day) to the smallest item (millisecond). However, it does not have to start with day, but with any of the other items. The first (largest) time-span item found:
1) will be incremented by the recalculated missing higher items.
2) It will have: default number of characters = *
, so as needed.
Items of time-span do not need be listed down to the smallest items either. It may end with any item. But then the information is lost in the text form. When converting back from text form to TimeSpan
form, these missing items are considered to be 0
Examples for TimeSpan 41/09:03:01.500
will be "+41/09:03:01.500"
will be "41/09:03:01.500"
will be "+041090301500"
will be "+993:03:01.500"
(993 = 41*24 + 9)
will be "+993:03:01"
(993 = 41*24 + 9)