[fpc-pascal] StrToTime function
Koenraad Lelong
fpascal at brouwerij.homelinux.net
Thu May 8 21:38:02 CEST 2008
Hello,
I need the StrToTime function, but it doesn't behave well I think. A
testprogram, running on Linux, compiled with fpc 2.2.0 :
program TimeTest;
uses sysutils;
var
i : integer;
DT : TDatetime;
T1Str : string;
T2Str : string;
begin
for i:=0 to 23 do
begin
T1Str:=IntToStr(i);
if Length(T1Str)<2 then
T2str:='0'+T1Str+':00'
else
T2Str:=T1Str+':00';
DT:=StrToTime(T2str);
writeln(i,' - ',T2str,' - ',DT);
end{for}
end.
The result :
0 - 00:00 - 0.000000000000000E+000
1 - 01:00 - 4.166666666666666E-002
2 - 02:00 - 8.333333333333333E-002
3 - 03:00 - 1.250000000000000E-001
4 - 04:00 - 1.666666666666667E-001
5 - 05:00 - 2.083333333333333E-001
6 - 06:00 - 2.500000000000000E-001
7 - 07:00 - 2.916666666666667E-001
8 - 08:00 - 3.333333333333333E-001
9 - 09:00 - 3.750000000000000E-001
10 - 10:00 - 4.166666666666667E-001
11 - 11:00 - 4.583333333333333E-001
12 - 12:00 - 0.000000000000000E+000
13 - 13:00 - 5.416666666666666E-001
14 - 14:00 - 5.833333333333334E-001
15 - 15:00 - 6.250000000000000E-001
16 - 16:00 - 6.666666666666666E-001
17 - 17:00 - 7.083333333333334E-001
18 - 18:00 - 7.500000000000000E-001
19 - 19:00 - 7.916666666666666E-001
20 - 20:00 - 8.333333333333334E-001
21 - 21:00 - 8.750000000000000E-001
22 - 22:00 - 9.166666666666666E-001
23 - 23:00 - 9.583333333333334E-001
The value for 12:00 is not right IMHO.
I briefly looked at the source to see how it works, but I don't see it
immediately.
Is this a known problem ? Is someone able to solve this in a few minutes ?
I'm willing to look into this but I would like to know if I'm doing
something wrong before I start.
B.T.W. I use this to define a time-duration, not some time of the day so
AM/PM is not appropriate.
Thanks,
Koenraad Lelong.
More information about the fpc-pascal
mailing list