Resolve the date time from the string based on the time date format

xiaoxiao2021-03-06  84

Parked the date time in the string according to the time date format (Const S, FMT: String; Dft: tdatetime): TDATETIME; FUNCTION STRTODTFMT (CONST S, FMT: String; Dft: tdatetime): TDATETIME; VAR PTS: array [ 1..10] OF INTEGER; WDS: Array [1..10] of integer; VLS: array [1..10] of Word; I, J, N, M, K, D: Integer; T: String; C: char; DT: TDATETIME; begin // only processes the date and time of digital format i: = 1; N: = 1; T: = Trim (ANSIUPPERCASE (FMT)); // Analytical format string while i <= length (t) Do Begin Case T [I] of 'Y': PTS [N]: = 1; 'M': PTS [N]: = 2; 'D': PTS [N]: = 3; 'h' : PTS [N]: = 4; 'N': PTS [N]: = 5; 's': PTS [N]: = 6; 'Z': PTS [N]: = 7; Else Begin i: = I 1; Continue; end; end; c: = t [i]; i: = i 1; m: = 1; while t [i] = c do begin inc (i); inc (M); end ; If t [i] in ['y', 'm', 'd', 'h', 'n', 's', 'z'] THEN WDS [N]: = M else WDS [N]: = 0; N: = N 1; IF n> 7 dam; end; N: = n - 1; // Start transformation result: = DFT; if longth (s) <= 0 THEN EXIT; D Ecodedate (Result, VLS [1], VLS [2], VLS [3]); Decodetime (Result, VLS [4], VLS [5], VLS [6], VLS [7]); M: = 1; I: = 1; k: = Length (s); while m <= n do beg, while not (s [i] in ['0' .. '9', # 0]) do INC (i); if i > k TEN BREAK; D: = 0; J: = I; while (s [i] in ['0' .. '9']) AND ((WDS [M] <= 0) OR (i - j < WDS [M])) Do Begin D: = D * 10 ORD (S [I]) - ORD ('0'); i: = i 1; End; VLS [PTS [M]]: = D;

转载请注明原文地址:https://www.9cbs.com/read-107047.html

New Post(0)