Formatting rule for time
DateTime specifies the text (formatted) form of the time. A properly created formatting rule allows bidirectional conversion between a text representation and a value of the
DateTime type without loss of information.
Formatting rule contains both constant items (e.g. separators inside time) and individual time items. The time items can be in any order. Each time item (day, hour, minute, etc.) has an identifier (character: D, H, M, etc.).
The time entry is indicated in the formatting rule by the percent sign
%, thus distinguishing it from constant items (separators). This is followed by an optional number of digits (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.). The time entry is terminated with the mandatory time entry identifier.
For example:
"%Y.%m.%d %H:%M:%S.%T"
Syntax of one time item:
%[*|1-9]id
Time items:
y - Only the last two digits of the year (e.g.
21) [
2 digits].
T - millisecond (
0-999) [
3 digits].
The number of digits here means the precision after the decimal separator, so 1=tenths, 2=hundredths, and 3=thousandths.
See the
PmDateObject.GetMillisecond method.
D - day of year (
1-366) [
3 digits].
It works only for converting the time (
DateTime) to the text form.
See the
PmDateObject.GetDayOfYear method.
Wi - week of year (
1-53) [
2 digits] according to
ISO 8601.
It works only for converting the time (
DateTime) to the text form.
See the
PmDateObject.GetWeekOfYear method.
ws - day of the week starting on Sunday (
0-6) [
1 digit].
It works only for converting the time (
DateTime) to the text form.
See the
PmDateObject.GetWeekday method.
wm - day of the week starting on Monday (
1-7) [
1 digit] according to
ISO 8601.
It works only for converting the time (
DateTime) to the text form.
Note! Time items do not all have to be entered. But then the information is lost in the text form. When converting back from text to
DateTime it
must not miss items from the date part (year, month, day). Other missing items are considered to be
0.
Examples for
DateTime 2022.07.01 09:03:01.500:
"%Y.%m.%d %H:%M:%S.%T" will be
"2022.07.01 09:03:01.500"
"%Y.%*m.%*d %H:%M:%S.%T" will be
"2022.7.1 09:03:01.500"
"%Y%m%d%H%M%S%T" will be
"20220701090301500"
"%Y.%m.%d" will be
"2022.07.01"
"%Y/%Wi" will be
"2022/26"