现在有这么一个字符串,想转换为Tdatetime格式,毫秒一定要保留
20:19:11:123
小时:分钟:秒:毫秒我用strtotime的时候总是出错,获得不了毫秒,
有人能帮忙解决下么?谢谢
已经知道
当有日期的时候,使用strtodatetime可以转换
但问题是现在没有日期,strtodatetime转换会出错希望大家尝试后再说结果哈~~谢拉~
20:19:11:123
小时:分钟:秒:毫秒我用strtotime的时候总是出错,获得不了毫秒,
有人能帮忙解决下么?谢谢
已经知道
当有日期的时候,使用strtodatetime可以转换
但问题是现在没有日期,strtodatetime转换会出错希望大家尝试后再说结果哈~~谢拉~
var
A : TDateTime;
begin
A := StrToTime('20:19:11.123');
ShowMessage (FormatDateTime('HH:NN:SS.ZZZ', A));
end;
这个解决了一定问题,一定给分,谢谢了
对问题重新描述下:现在有这么一个字符串,想转换为Tdatetime格式,毫秒一定要保留
20:19:11:123
小时:分钟:秒:毫秒 用strtotime的时候,默认字符串格式为20:19:11.123 (小时:分钟:秒.毫秒,注意这里是.)我想问下有没有一个像DateSeparator那样的全局变量,可以设置分隔符为:的变量?
(因为现在的格式使用strtotime会产生异常,而我不想每次都替换字符串中的毫秒分隔符.)
写个函数把第三个':'替换为'.'就行了:
function MyStrToTime(S: String): TDateTime;
var
i, j: Integer;
begin
j := 0;
for i := 1 to Length(S) do
begin
if S[i] = ':' then
begin
inc(j);
if j = 3 then
begin
S[i] := '.';
break;
end;
end;
end;
Result := StrToTime(S);
end;......var
A : TDateTime;
begin
A := MyStrToTime('20:19:11:123');
ShowMessage (FormatDateTime('HH:NN:SS:ZZZ', A));
end;