|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Operations |
MiniRobotLanguage (MRL)
DTO.fmt Command
Format time components into a string
Intention
This command assembles a time string from individual numeric components (Hour, Minute, Second, and optionally fractional seconds) based on a specified format mask. It is the counterpart to DTO.splittime and DTO.ParseTime.
The format mask defines the output structure using these components:
• HH (2-digit hour), H (1-2 digit hour)
• MM (2-digit minute), M (1-2 digit minute)
• SS (2-digit second), S (1-2 digit second)
• .XXXX (4-digit fractional part, 1/10000ths of a second)
Syntax
DTO.fmt|$$MSK|$$HRS|$$MIN|$$SEC[|$$MIC][|$$RET]
DTO.formattime|...
Parameter Explanation
P1 - $$MSK (Required)
The format mask string (or variable) defining the output format.
Example: "HH:MM:SS"
P2 - $$HRS (Required)
The numeric value for Hours (0-23) (or a variable, e.g., $$HRS).
P3 - $$MIN (Required)
The numeric value for Minutes (0-59) (or a variable, e.g., $$MIN).
P4 - $$SEC (Required)
The numeric value for Seconds (0-59) (or a variable, e.g., $$SEC).
P5 - $$MIC (Optional)
The numeric value for Fractional Seconds (0-9999) (or a variable, e.g., $$MIC). If omitted, 0 is used.
P6 - $$RET (Optional)
The variable (e.g., $$RET) to store the formatted time string. If omitted, the result is placed on TOS.
Example
'**********************************************
' DTO.fmt - Sample
'**********************************************
'
' --- Example 1: Format with fractional seconds ---
$$H = 14
$$M = 30
$$S = 45
$$F = 1234 ' Fractional part (1/10000ths)
$$MSK = "HH:MM:SS.XXXX"
DTO.fmt|$$MSK|$$H|$$M|$$S|$$F|$$RES
DBV.Result 1: $$RES ' Result: "14:30:45.1234"
'
' --- Example 2: Format with different mask (single digits) ---
$$H = 8
$$M = 5
$$S = 20
$$MSK = "H.M.S"
DTO.fmt|$$MSK|$$H|$$M|$$S||$$RES
DBV.Result 2: $$RES ' Result: "8.5.20"
'
' --- Example 3: Reordered mask and leading zeros ---
$$MSK = "SS-MM-HH"
DTO.fmt|$$MSK|9|12|7||$$RES
DBV.Result 3: $$RES ' Result: "07-12-09"
'
ENR.
Remarks
This command is useful for creating time strings for display or logging.
Note that the fractional component $$MIC is 0-9999 (1/10000ths). This differs from the newer DTO.ParseTime which uses milliseconds (0-999).
Limitations
- The command requires at least P1-P4 (Mask, Hour, Minute, Second). It will error if they are not provided.
- Input values are not strictly validated. Providing an hour of "25" might produce "25" in the string, rather than an error.
See also
• DTO.Parse Time - parse time into components
• DTO.Split Time Mask - (Old parsing command)
• DTO.Reformat Time - reformat time using mask
• DTO.Format Date - format date components to string
• DTO.Make Time Mask - create time format mask