1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
| uses System.SysUtils, System.RegularExpressions;
function StrToTimeEx(const AValue: String): TTime; var RegEx: TRegEx; Match: TMatch; begin RegEx := TRegEx.Create('(([0-9]{1,2})?:)?([0-9]{1,2}):([0-9]{1,2})[\.,]([0-9]{1,3})'); Match := RegEx.Match(AValue); if Match.Success and (Match.Length = Length(AValue)) then if Match.Groups[2].Length > 0 then Result := EncodeTime(StrToInt(Match.Groups[2].Value), StrToInt(Match.Groups[3].Value), StrToInt(Match.Groups[4].Value), StrToInt(Match.Groups[5].Value)) else Result := EncodeTime(0, StrToInt(Match.Groups[3].Value), StrToInt(Match.Groups[4].Value), StrToInt(Match.Groups[5].Value)) else raise EConvertError.Create(Format('"%s" is no valid time!', [AValue])); end;
ShowMessage(FormatDateTime('hh:nn:ss,zzz', StrToTimeEx('11:22.333'))); |